This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Sending and Receiving Messages Using Queues

This sample demonstrates how persistent queues can be created and used in WSO2 Message Broker using the JMS API. It first introduces a sample JMS client named QueueSender which is used to send messages to a known, created queue in WSO2 Message Broker. Then it introduces a sample JMS client named QueueReceiver to receive messages and print them in the console.

Prerequisites

See Prerequisites to Run the MB Samples for a list of prerequisites.

About the sample

The <MB_HOME>/Samples/JMSQueueClient/src/org/sample/jms directory has the following classes:

The following should be noted if you are writing a similar sample:

  • It is not possible to use the @ symbol in the username or password.

    It is also not possible to use the percentage (%) sign in the password. When building the connection string URL inside the andes client code of MB, the URL is parsed. This parsing exception happens because the percentage (%) sign acts as the escape character in URL parsing. If using the percentage (%) sign in the connection string is required, use the respective encoding character for the percentage (%) sign in the connection string. For example:

    If you need to pass adm%in as the password, then the % should be encoded with its respective URL encoding character. Therefore, you have to send it as adm%25in.

    For a list of possible URL parsing patterns, see URL encoding reference.
     

  • In addition to using javax.jms.QueueSender class to send the messages you can also use a javax.jms.MessageProducer client and send the messages to a destination queue. Following is the way of creating a JMS MessageProducer.

    javax.jms.MessageProducer messageProducer = queueSession.createProducer(queue);

    messageProducer.send(textMessage);

    messageProducer.close();
     

  • When subscribing and publishing to a queue in a tenant the qualified queue name, DOMAIN_NAME/Queuename should be given as follows.

    String queueName = "mydomain.com/testQueue";

    Queue queue = (Queue) ctx.lookup(queueName);

    See Managing Tenant-specific Subscriptions for more information.

Building the sample

Run the ant command from <MB_HOME>/Samples/JMSQueueClient directory.

Analyzing the output

You will get the following log in your console.

[java] Got message from queue receiver==>Test Message Content

To view the queue in the MB Management Console, log into the MB Management Console. Then click  Browse under  Queus in the  Main  tab. You will see a queue named TestQueue automatically created