APIs by Example: User Queues, Part 2

In the January 29, 2004, issue of this newsletter, Carsten Flensburg demonstrated how to create a CRTUSRQ command that you can use to create user queues. In this issue, he demonstrates how to use user queues in your applications.

Functionally, user queues are very much the same as data queues. They provide a means of communication between different programs in an asynchronous fashion. Like data queues, messages on a user queue can be sent in either keyed or arrival sequence. User queues are much faster than data queues but are a little more complicated to implement.

The first sample program, CBX1150, demonstrates the steps that you need to take when working with user queues. It creates a user queue, resolves a system pointer to it, enqueues a message, and then dequeues that message. Demonstrations are provided for both keyed and non-keyed user queues.

Since there are no APIs to read data from or write data to a user queue, it’s necessary to call either MI built-in functions or functions from the ILE C runtime library. CBX1150 demonstrates both of these techniques.

You should run the CBX1150 program in debug mode so you can see the steps it takes and observe the results of those steps. Instructions for both compiling and running this sample program are included at the top of the source member.

The second sample program demonstrates using a user queue to communicate between a client and server program. The client program asks the user for a string to convert to hex and sends it, by way of the user queue, to the server program. The server program does the work of converting it to hex and then sends it back to the client program to display to the user.

Both the client and server programs are launched from the CBX115 CL program. Instructions for compiling and running this sample application are listed at the top of the CBX115, CBX1151, and CBX1152 source members.

Download the save file containing the source code.

Read the entire article

One thought on “APIs by Example: User Queues, Part 2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s