More Message Queues

So my day job has been keeping me very busy (which is never a bad thing)...

 I have managed to delve a little deeper into message queues, and although documentation exists, it can be a little ambiguous.  Here is what I have found...

NAV and Message Queues

  WritePrivateQueue()

CREATE(CC2);

CREATE(MQBus);

CC2.AddBusAdapter(MQBus,1);

MQBus.OpenWriteQueue('.\private$\TestWriteQueue',0,0);

MQBus.SenderAuthenticationLevel:= 2;

OutMsg := CC2.CreateoutMessage('Message queue://.\private$\TestWriteQueue');

OutS := OutMsg.GetStream();

OutS.WRITE('Hello world! - WritePrivateQueue');

OutMsg.Send(0);

 

Variables

Name DataType Subtype
MQBus Automation 'Navision MS-Message Queue Bus Adapter'.MSMQBusAdapter
CC2 Automation 'Navision Communication Component version 2'.CommunicationComponent
OutMsg Automation 'Navision Communication Component version 2'.OutMessage
OutS OutStream  
 

The code above will write to a new private message queue on the local machine called: TestWriteQueue

The message is called: Navision MSMQ-BA

 

At the same time a message called: Navision MSMQ-BA is created in the public queue called: nsadminreceivequeue - not too sure what this one does or is as it is blank – it seems to be the admin queue used to deliver the message to the correct queue as it states – “The message reached the queue.”

 


 

Receiving & Displaying Messages OnRun()

CREATE(MQBus);

CREATE(CC2);

CC2.AddBusAdapter(MQBus,1);

MQBus.OpenReceiveQueue('.\private$\TestWriteQueue',0,0);

 CC2::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")

InMsg := InMessage;

InS := InMsg.GetStream();

InS.READ(Txt);

MESSAGE(Txt);

InMsg.CommitMessage();

  
Name DataType Subtype Length
MQBus Automation 'Navision MS-Message Queue Bus Adapter'.MSMQBusAdapter  
CC2 Automation 'Navision Communication Component version 2'.CommunicationComponent WITHEVENTS
InMsg Automation 'Navision Communication Component version 2'.InMessage  
InS InStream    
Txt Text   100
 

This code will receive the message sent by WritePrivateQueue and then display the text in message in NAV.  This codeunit must be running single instance so that it can respond to the event.

  


 

WritePrivateQueueandReply()

CREATE(CC2);

CREATE(MQBus);

CC2.AddBusAdapter(MQBus,1);

MQBus.OpenWriteQueue('.\private$\TestWriteQueue',0,0);

MQBus.OpenReplyQueue('.\private$\TestReadQueue',0,0);

MQBus.SenderAuthenticationLevel:= 3;

OutMsg := CC2.CreateoutMessage('Message queue://.\private$\TestWriteQueue');

OutS:= OutMsg.GetStream();

OutS.WRITE('Hello world! - WritePrivateQueueandReply');

InMsg:= OutMsg.SendWaitForReply(3000);

IF ISCLEAR(InMsg) THEN

  MESSAGE('InMsg not received')

ELSE

BEGIN

  InS:= InMsg.GetStream();

  InS.READ(Txt);

  MESSAGE(Txt);

END;

 

Variables

Name DataType Subtype Length
MQBus Automation 'Navision MS-Message Queue Bus Adapter'.MSMQBusAdapter  
CC2 Automation 'Navision Communication Component version 2'.CommunicationComponent  
OutMsg Automation 'Navision Communication Component version 2'.OutMessage  
OutS OutStream    
InMsg Automation 'Navision Communication Component version 2'.InMessage  
InS InStream    
Txt Text   100
 

The code above will write to a new private message queue on the local machine called: TestWriteQueue

The message is called: Navision MSMQ-BA

 

At the same time a message called: Navision MSMQ-BA is created in the public queue called: nsadminreceivequeue - not too sure what this one does or is as it is blank – it seems to be the admin queue used to deliver the message to the correct queue as it states – “The message reached the queue.”

 

This time we wait for a response back after sending the machine.

The system is not receiving the reply!!!

 


 

Public/Private Queues

A public queue is a queue that is registered in the directory service that any Message Queuing application can locate. Public queues are persistent. You can make a backup of their registration information, which makes them suitable for long-term use.

A private queue is a queue that is registered on the local computer (not in the directory service) that other applications typically cannot locate. Private queues have the advantage of having no directory service overhead. This means that they are faster to create, there is no latency and no replication. Further, they can be created and deleted when the directory service is not working.

   

 

Comment List
  • Hi. Nice post.

    I'm trying your code to receive a message from an external application to Navision however it doesn't read it. I can only write. I'm using your exact code in the onRun() trigger. Am i missing something?

Related
Recommended