Ruskin
31st May 2002, 01:13
When the DDC Driver is activated, from Baan, it runs the driver, passing the in, out and download queues. Thus, the driver then responds with a DDC_ACK to let Baan know, that the driver is activated. To do this, the driver must write to the 'In Queue', using a "sender key" functionality. The issue, is how do you read and write to these queues in NT. The files themselves do NOT contain anything. IE: suppose we have the following script;
long m.id
long i
string r.m(255)
m.id = open.message(1,"d:\baan\lib\queue.out",0)
if m.id = -1 then
message("Error opening file")
else
i = send.message(m.id, 0, "0,DDC_ACK")
if i = 0 then
i = recv.message(m.id, 0, 1000, r.m)
if i = -1 then
message("Failed")
else
message(r.m)
endif
else
message("Failed")
endif
close.message(m.id)
endif
If we put this into debug, and step through the script, the D:\BAAN\LIB\QUEUE.OUT file is NEVER changed (ie: it remains at 0 bytes). Therefore, if an external application sent a message to this file, how does it write to the file. For example, using VB to write to the file, like;
Open "d:\baan\lib\queue.out" For Append As #1
Print #1, "0,DDC_ACK"
Close #1
Does not work.... (It does write to the file, but the recv.message function, in Baan, will not read it). What is the correct method to read/write to the DDC message queue files in NT?
rupertb
5th August 2002, 15:05
Hi there, I've just started dabbling with DDC - of course I've printed all posts with respect to this to try and help myself along. I think I have an answer to your question: Baan uses the IPC (interprocess communication) functionality to connect DDC with other applications running on the same machine. Under the topic 'mail' in the baan tools help the following statements lept out at me:
long OPEN.MESSAGE ( long project,
string name(132),
long action )
DESCRIPTION
long OPEN.MESSAGE( long project, string name(132),
long action )
This function opens a mailbox in which messages can be placed
and from which messages can be read.
The project variable is a number (1-255) indicating the project
to which the mailbox belongs.
The name variable identifies an unique mailbox within the
specified project. This variable should contain the name of a
file which is readable for all users that want to use the
mailbox. To generate an unique key identifying the mailbox,
the project number and inode number of the specified file are
taken. Within a project the name should be clearly associated
with a particular mailbox.
The contents of the specified file is not used or changed.
The action argument may have the following values:
0: If the mailbox does not exists, a new one is created.
1: Same as 0, except that a "unique" filename is created by
the system ("$BSE/TMP/PostB<pid>" is created), so the
name argument should be given as the empty string ("").
2: No new mailbox is created if it does not exist.
This function returns the identification of the opened mailbox. If
an error occurred, -1 is returned and the variable e contains
the error number.
A bit late, but I hope it helps regardless,
Rupert
patvdv
5th August 2002, 15:18
Please use our own on-line Programmer's Guide http://www.baanboard.com/programmers_manual_baanerp for referencing function syntax. You can find the latest syntax information on this function here: http://www.baanboard.com/programmers_manual_baanerp_help_functions_interprocess_communication_os_level_open_message
Ruskin
5th August 2002, 23:26
sorry, I must have not been to specified. I have no problem with the;
open.message()
send.message()
recv.message()
close.message()
functions from within Baan. The issue I have, is using a third party product to read and write to the same message queues. For example, if I used VB, how do I read/write to the same message queues....
I think it has something to do with MSMQ (Message Queue) objects.
rupertb
6th August 2002, 11:00
Hi Ruskin - I see your problem in your VB code example you are using file access commands, however the message queue should be accessed using MSMQ type commands - sorry I don't do Visual Basic at all:
-------------------- Writing to Queue ---------------------------
using System;
using System.Messaging;
public class MQSend
{
public static void Main(String[] args)
{
string mqPath = ".\\private$\\MyQueue2";
if (!MessageQueue.Exists(mqPath))
{
MessageQueue.Create(mqPath);
}
MessageQueue mq = new MessageQueue(mqPath);
mq.Send("whateverdata");
}
}
-------------------- Reading from Queue ---------------------------
using System;
using System.Messaging;
using System.IO;
using System.Runtime.Serialization;
public class MQReceive
{
public static void Main()
{
string mqPath = ".\\private$\\MyQueue2";
if ( !MessageQueue.Exists(mqPath) )
{
Console.WriteLine("The queue '" + mqPath + "' does not exist!");
return;
}
MessageQueue mq = new MessageQueue(mqPath);
((XmlMessageFormatter)mq.Formatter).TargetTypeNames = new string[]{"System.String"};
try
{
Message m = mq.Receive(new TimeSpan(0,0,3));
Console.WriteLine("Message: " + (string)m.Body);
}
catch ( MessageQueueException )
{
Console.WriteLine("There are no messages in the queue");
return;
}
catch ( InvalidOperationException )
{
Console.WriteLine("The message removed from the queue is not a string");
return;
}
}
}
Also check your Message Queue Services setup on your server.
Be carefull in making any changes to these settings on your live server as other systems may use the MQS - the setting provided here are for 'workgroup mode'.
rupertb
6th August 2002, 11:21
Sorry forgot to attach the screenshots!