Привет всем. Ненашел на форуме ответа по этой теме.. Привожу пример как работать с MSMQ в Дельфи 5,6,7
Заходим в добавление/удаление компонентов винды, находим там "Message Queuing" ставим галочку. заходим в дельфи - Project > Import Type Lybrary ищем "Microsoft Message Queue 2.0 Object Library" устанавливаем.
версию 3.0 неустанавливайте - матерится... я неразберался что к чему. Остановился на 2.0
Заходим в консоль управления компьютером. Ищем раздел "Message Queuing" ищем "Public Queues" тыцяем правой кнопок мыши и создаем новую очередь например с именем "MyQueue"
Теперь в дельфи пишем:
| Код | uses ... MSMQ_TLB, OleServer, ComCtrls, ComObj;
procedure TForm1.SendNewMSMQMessage(Sender: TObject); const cntFormatName = 'DIRECT=TCP:127.0.0.1\MyQueue'; // MyQueue - название очереди которую Вы создали var aInfo: TMSMQQueueInfo; aQueue: IMSMQQueue2; aMessage: TMSMQMessage; begin aInfo := TMSMQQueueINfo.Create(self); aInfo.FormatName := cntFormatName; aQueue := aInfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE); try aMessage := TMSMQMessage.Create(self); aMessage.Label_ := 'My Test Message'; aMessage.Body := 'Hello, World!'; aMessage.Send(aQueue); finally aQueue.Close; end; end;
procedure TForm1.ReadMSMQMessages(Sender: TObject); const cntQueueName = 'DIRECT=TCP:192.168.14.64\MyQueue'; // MyQueue - название очереди которую Вы создали var aQueueInfo: IMSMQQueueInfo; aQueue: IMSMQQueue; aMessage: IMSMQMessage; aTransaction, aWantDestination, aWantBody, aRecieveTimeout, aInputData, aInputLabel: OLEVariant; begin aQueueInfo := CreateCOMObject (CLASS_MSMQQueueInfo) as IMSMQQueueInfo; aQueueInfo.FormatName := cntQueueName; aQueue := aQueueInfo.Open (MQ_RECEIVE_ACCESS, MQ_DENY_NONE); try aTransaction := MQ_SINGLE_MESSAGE; aWantDestination := True; aWantBody := True; aRecieveTimeout := 1000; aMessage:= aQueue.Receive (aTransaction, aWantDestination , aWantBody , aRecieveTimeout); if aMessage<> nil then begin aInputData:= aMessage.body; aInputLabel:=msg.label_; ShowMessage(Format('Label: %s, Body: %s', [aInputLabel, aInputData])); end; finally queue.close; end; end;
|
|