Building Data Agents Using the Messaging Functions
Contents
Building Data Agents Using the Messaging Functions
What Is Message Queuing
Message queuing is a communication tool that allows applications to reliably interconnect. The queue acts as a holding container for messages as they are sent between applications. The applications send messages to and read messages from queues to communicate back and forth. An application writes a message to a queue, which will then be received and processed by another application at some point determined by the receiving application. This type of communication is designed for asynchronous use where the applications involved are not waiting for an immediate response from the other end.
What are Data Agents
Data agents are applications written in the Recital scripting language that use the message queue functions to manage the transmitted data. Typically a data agent runs in the background reading data from the message queue and processing it. Any Recital application can open a message queue and transmit data to the Data Agent.
Building a Simple Data Agent
In this simple Data Agent example we will open a queue called recital_queue which sends XML encoded messages.
First we need to open a the queue
mqdes=mqopen("/recital_queue") // Check for error if (mqdes < 0) debug(strerror(error())) return endif
Then we need to wait in a loop processing incoming data.
do while .t. // Read each message do while (mqcurmsgs(mqdes) > 0) // Read the next message mstr=mqreceive(mqdes) // Decode the xml message obj1 = xml_decode(mstr) // TODO... process the message enddo // wait 1 second before retrying sleep 1 enddo
When we have finished we can close the queue
mqclose(mqdes)