Receiving a Document - Code Example 2

In this example, we use a single instance codeunit to initialize the Navision Communication Component, establish contact to a Navision MS-Message Queue Bus Adapter, open the bus adapter's receive queue, read the message that is received and then send a reply.

For the purpose of this example, we have defined the following variables:

Variable Name

Data Type

Subtype

Length

MQBus

Automation

'Navision MS-Message Queue Bus Adapter'.MSMQBusAdapter

 

CC2

Automation

'Navision Communication Component version 2'.CommunicationComponent

 

InMsg

Automation

'Navision Communication Component version 2'.InMessage

 

InS

InStream

 

 

Txt

Text

 

100

OutMsg

Automation

'Navision Communication Component version 2'.OutMessage

 

OutS

OutStream

 

 

Note that in the following example, you can use .\MyQueue (instead of MyMessageQueueServer\MyQueue) if you have installed the Microsoft Message Queue Server on your local machine.

Example

OnRun()

CREATE(MQBus);

CREATE(CC2);

MQBus.OpenReceiveQueue('MyMessageQueueServer\comcom2_queue',0,0);

CC2.AddBusAdapter(MQBus,1);

CC2::MessageReceived(VAR InMessage : Automation)

InMsg:= InMessage;

IF (InMsg.ExpectReply) THEN

BEGIN

  InS:= InMsg.GetStream();

  InS.READ(Txt);

  MESSAGE(Txt);

  OutMsg:= InMsg.CreateReply();

  OutS:= OutMsg.GetStream();

  OutS.WRITE('Yes, hello world! OK.');

  OutMsg.Send(0);

END;

InMsg.CommitMessage();