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/.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

This sample demonstrates how a message expiration time can be set for messages sent to WSO2 MB.

Prerequisites

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

About the sample

In this sample, a JMS subscriber connects to WSO2 MB and publishes messages to a queue using a 'transacted' session. Using this session ensures that the messages published will persist in WSO2 MB (i.e. will be stored to the DB) only when they are committed. Therefore, as demonstrated by this sample, publishing messages to WSO2 MB through a transacted session involves two steps:

  1. The messages have to be sent from the publisher client.
  2. The messages have to be committed from the publisher client.

The <MB_HOME>/Samples/JMSQueueClient/src/org/sample/jms directory has the following classes implementing the behaviour explained above.

Building the sample

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

Analyzing the output

The result log shown above explains how the transactional session has worked when publishing messages:

[java] INFO : org.sample.jms.MainClass - ------Sample for Message Sending and Committing.------
[java] INFO : org.sample.jms.TransactionalQueuePublisher - Message sent : My First Message.
[java] INFO : org.sample.jms.QueueConsumer - No messages were received within 5 seconds.
[java] INFO : org.sample.jms.TransactionalQueuePublisher - Message sent : My Second Message.
[java] INFO : org.sample.jms.TransactionalQueuePublisher - Committing messages.
[java] INFO : org.sample.jms.QueueConsumer - Received message : My First Message.
[java] INFO : org.sample.jms.QueueConsumer - Received message : My Second Message.
[java] INFO : org.sample.jms.MainClass - ------Sample for Message Sending, Rollback and Committing.------
[java] INFO : org.sample.jms.TransactionalQueuePublisher - Message sent : My Third Message.
[java] INFO : org.sample.jms.QueueConsumer - No messages were received within 5 seconds.
[java] INFO : org.sample.jms.TransactionalQueuePublisher - Rollbacks all uncommitted messages.
[java] INFO : org.sample.jms.TransactionalQueuePublisher - Message sent : My Forth Message.
[java] INFO : org.sample.jms.TransactionalQueuePublisher - Committing messages.
[java] INFO : org.sample.jms.QueueConsumer - Received message : My Forth Message.
[java] INFO : org.sample.jms.QueueConsumer - No messages were received within 5 seconds.
[java] INFO : org.sample.jms.TransactionalQueuePublisher - Shutting down publisher.
[java] INFO : org.sample.jms.QueueConsumer - Shutting down consumer.
  • No labels