Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Message Queuing Applications Message queuing applications can be divided into tw

ID: 3531862 • Letter: M

Question

Message Queuing Applications

Message queuing applications can be divided into two categories: sending applications (Senders), which send messages to queues, and receiving applications (Receivers), which read messages in queues and can remove messages from queues.

Senders

Senders send messages to a queue, not to the receiving application. Using a queue as the destination allows the sending application to operate independently of the receiving application.

Receiving applications

Receivers read the messages in the queue in two different ways. The receiving application can peek at a message in the queue, leaving the message in the queue, or it can retrieve the message, taking the message out of the queue.

Design and write an application that will send several messages to a queue. The messages will need to be read by a function in your application. The messages you should send should be similar to the following:

"3 * 4 + 6 / 3",

"3 * 4 + 5 / 6",

"3 - 4 / 0",

"3 + 4 * 5 - 6",

"3 + 5 +",

"(3 - 4) / (5 - 6)",

"5 *",

"(3 - 4) * 5 / 6",

"/ 7 + 4",

"2 + 3 * 4 / 2"

You will be provided with a header file

Explanation / Answer

Sending Messages (Sender Specific)

The queue sender creates a sender, constructs a text message, and sends the text message using the sender. The message and the sender are then explicitly deallocated.

// Sender-specific code

QueueSender *sender = sess->createSender(queue);

// Create and send message

Message *msg = sess->createTextMessage(to_wstring(argv[2]));

sender->send(msg);

sender->close();

delete msg;

delete sender;

Receiving Messages (Receiver Specific)

The queue receiver creates a receiver, waits for a text message, prints the text message, closes the receiver, and deallocates the message and the receiver.

// Receiver-specific code

QueueReceiver *receiver = sess->createReceiver(queue);

// Receive message

Message *msg = receiver->receive();

TextMessage *tm = dynamic_cast<TextMessage*>(msg);

if(tm != NULL)

cout << "Received message: " << tm->getText() << endl;

receiver->close();

delete msg;

delete receiver;