Looking into queues

While debugging workflows communicating via queue services, soon you will need to see what is inside the queues. As long as you use SQL Server based queue service, you might do that via SQL queries. However, messages are usually binary serialized and sometimes compressed, so all you can easily check is whether a message arrived or not, but it will be difficult for you to see the contents of a message. To simplify the task, the Flower management API provides an object to manipulate queues.

You can get an object representing a queue by calling 'queue' function. The function accepts the path to the queue service.

var q = queue('/Services/SomeServiceContainer/Qeueue');


You can get a default queue of a processor by using the same function.

var procQueue = queue('/Processors/DefaultProcessor/queue');


To get messages, you need to know a recipient id. In general case, they are generated by applications. For default queues the recipient ids have the following format: '<pid>/<message-full-type-name>'. For example, '#123456/System.String'.

You can get an array of all recipient ids by calling 'getRecipients'. The method accepts a range specifying the offset and the limit of the frame of recipient ids to return.

var recipientIds = q.getRecipients(0, 1000);


Having the recipient id, you can get the messages by using 'getMessagesByRecipient' method. It accepts an array of recipient ids and a timespan to filter the messages by the arrival time. The timespan is optional; if not specified, all messages of the recipients are returned.

The following code gets messages of a recipient 'recipientId' arrived in the last 10 minutes:

var start = new Date();
var end = ((end = new Date()).setMinutes(end.getMinutes() - 10), end);

var messages = q.getMessagesByRecipient([recipientId], start, end);


If there are any messages, you will get an array of objects with the following attributes:

{
    id: '########-####-####-####-############', //Id of the message.
    recipient: '#12345/TypeName', //Recipient of the message.
    putOn: ##/##/#### ##:##:##, //When the message has arrived.
    data: XML //The payload.
}


The Flower management console prints JSON if the last command has been evaluated to an object, so you can inspect a message simply by entering its name in the console. You can inspect the message data by evaluating the 'data' attribute of a message. To write the data to a file, use '$fs' object.

$fs.print('message.xml', messages[0].data);


Having a message id, you can get the message by calling 'getMessagesById' (the method accepts an array of ids).

If, by some reason, your system generates lost messages, you can remove them by calling 'removeMessages'. You can also remove an entire recipient by calling 'removeRecipients'.

Last edited Oct 31, 2013 at 6:55 PM by dbratus, version 1

Comments

No comments yet.