Ubik Batch Server JMS Batches

From UbikWiki

Contents

Use case

This feature is useful when extracting data from:

  • Message Oriented Middleware (ActiveMQ, Open JMS, Tibco, IBM MQ Series, WebMethods ...)
  • Enterprise Service Bus (OpenESB, Mule)

Introduction

This feature is available since version 5.0.1.0. It enables using Topics and Queues as data sources for a Batch. All options available on a JMS session can be set on the batch start:

  • Transacted / Not Transacted
  • Acknowledge modes (AUTO ACK, DUPS, Client Acknowledge)
  • Topic subscription
  • JMS 1.1 and 1.0.2 are supported
  • ...

Note about our implementation:

  • A different JMS Session is associated to each batch thread

Note about Transaction and Ack modes

Acknowledgement options:

  • Auto mode: When a session uses auto mode, the messages sent or received from the session are automatically acknowledged. This is the simplest mode and expresses JMS's power by enabling once-only message delivery guarantee. The JMS provider carefully manages message redelivery and guarantees once-only delivery semantics.

What does this mean ? Each message that your get in executeOnBlock has been acknowledged (no more on the broker), so it is up to you to guarantee that it is not lost.

  • Duplicates okay mode: When a session uses duplicates okay mode, the messages sent or received from the session are automatically acknowledged just like auto mode, albeit lazily. Under rare circumstances, the messages might be delivered more than once. This mode enables at-least-once message delivery guarantee.

What does this mean ? Each message that your get in executeOnBlock has been acknowledged (no more on the broker), so it is up to you to guarantee that it is not lost. Furthermore you must handle the fact that you can receive duplicated.

  • Client mode: When a session uses client mode, the messages sent or received from the session are not acknowledged automatically. The application must acknowledge the message receipt. This mode gives the application (rather than the JMS provider) complete control over message acknowledgement, at the cost of increased code complexity.

What does this mean ? It means that the message must be acked by you to disappear from the broker. Call acknowledge() on IMessageHolder. Note that the acknowledge applies to all messages consumed since last ack (in the same thread).

Transaction options:

  • Transacted session: An application can participate in a transaction by creating a transacted session (or local transaction). The application completely controls the message delivery by either committing or rolling back the session.

What does this mean ? Ack modes are not used. Calling the commit() method commits all the messages the session receives. Similarly, calling the rollback() method rejects all the messages the session receives.

For a more detailed explanation, read: Transaction and redelivery in JMS

Coding:

Example:

protected void executeOnBlock(IJmsMessageHolder[] data) throws Exception {
		for (int i = 0; i < data.length; i++) {
			IJmsMessageHolder holder = data[i];
			Message message =  holder.getUnderlyingMessage();
			Person person = (Person)holder.getMappedData();
		}
	}

Configuration:

Use:

Sample BatchStart that configures a JMS datasource that uses the following parameters to connect to the queue:

  • java:comp/env/jms/localConnectionFactory
  • java:comp/env/jms/localDemoQueue

This batch will use a JMS session with the following characteristics:

  • Auto acknowledge
  • Not Transacted
JmsBatchStart batchStart = new JmsBatchStart();
batchStart.setMapperClassName(PersonMapper.class.getName());
batchStart.setConnectionFactoryName("java:comp/env/jms/localConnectionFactory");
batchStart.setDestinationName("java:comp/env/jms/localDemoQueue");
batchStart.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
batchStart.setSessionTransacted(false);

Declare in bar.xml the following resources:

<bar-resource name="jms/localConnectionFactory" type="javax.jms.ConnectionFactory" />
<bar-resource name="jms/localDemoQueue" type="javax.jms.Queue" />
Personal tools