SJMS Component
Available as of Camel 2.11
This component is under active development.
The SJMS Component is a JMS client for Camel based purely on the JMS API. It will be released as part of Camel 2.11 with the following functionality:
- Queue and Topic Support (Durable & Non-Durable)
- InOnly & InOut Support
- Plugable Connection Resource Management
- Session, Consumer, & Producer Pooling & Caching Management
- Asynchronous Producer and Consumer Processing
- Internal JMS Transaction Support
Why the S in SJMS
S stands for Simple and Standard and Springless. Also camel-jms was already taken.
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-sjms</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
URI format
sjms:[queue:|topic:]destinationName[?options]
Where destinationName
is a JMS queue or topic name. By default, the destinationName
is interpreted as a queue name. For example, to connect to the queue, FOO.BAR
use:
sjms:FOO.BAR
You can include the optional queue:
prefix, if you prefer:
sjms:queue:FOO.BAR
To connect to a topic, you must include the topic:
prefix. For example, to connect to the topic, Stocks.Prices
, use:
sjms:topic:Stocks.Prices
You append query options to the URI using the following format, ?option=value&option=value&...
SjmsComponent Options and Configurations
Below is an example of how to configure the SjmsComponent with its required ConnectionFactory provider. It will create a single connection by default and store it using the components internal pooling APIs to ensure that it is able to service Session creation requests in a thread safe manner.
SjmsComponent component = new SjmsComponent(); component.setConnectionFactory(new ActiveMQConnectionFactory("tcp://localhost:61616")); getContext().addComponent("sjms", component);
For a SjmsComponent that is required to support a durable subscription, you can override the default ConnectionFactoryResource instance and set the clientId property.
ConnectionFactoryResource connectionResource = new ConnectionFactoryResource(); connectionResource.setConnectionFactory(new ActiveMQConnectionFactory("tcp://localhost:61616")); connectionResource.setClientId("myclient-id"); SjmsComponent component = new SjmsComponent(); component.setConnectionResource(connectionResource); component.setMaxConnections(1);
Producers
The SjmsProducer Endpoint supports the following properties:
Option |
Default Value |
Description |
---|---|---|
|
|
The JMS acknowledgement name, which is one of: |
|
|
InOut only. Defines the number of MessageListener instances that for response consumers. |
|
|
Sets the Producers message exchange pattern. |
|
|
InOut only. Specifies a named reply to destination for responses. |
|
|
Whether a message should be delivered with persistence enabled. |
|
|
Defines the number of MessageProducer instances. |
|
|
InOut only. Specifies the amount of time an InOut Producer will wait for its response. |
|
|
Sets whether the Endpoint will use synchronous or asynchronous processing. |
|
|
If the endpoint should use a JMS Session transaction. |
|
|
Disabled by default. Sets the Message time to live header. |
Consumers
The SjmsConsumer Endpoint supports the following properties:
Option |
Default Value |
Description |
---|---|---|
|
|
The JMS acknowledgement name, which is one of: |
|
|
Defines the number of MessageListener instances. |
|
|
Required for a durable subscriptions. |
|
|
Sets the Consumers message exchange pattern. |
|
|
Sets the message selector. |
|
|
Sets whether the Endpoint will use synchronous or asynchronous processing. |
|
|
If the endpoint should use a JMS Session transaction. |
|
|
Disabled by default. Sets the Message time to live header. |
Examples
InOnly Producer - (Default)
The InOnly Producer is the default behavior of the SJMS Producer Endpoint.
from("direct:start") .to("sjms:queue:bar");
InOut Producer
To enable InOut behavior append the exchangePattern
attribute to the URI. By default it will use a dedicated TemporaryQueue for each consumer.
from("direct:start") .to("sjms:queue:bar?exchangePattern=InOut");
You can specify a namedReplyTo
though which can provide a better monitor point.
from("direct:start") .to("sjms:queue:bar?exchangePattern=InOut&namedReplyTo=my.reply.to.queue");
When using InOut with SJMS in a clustered environment you must either use TemporaryQueue destinations or use a unique named reply to destination per instance. Message correlation is handled by the endpoint, not with message selectors at the broker.
Does Springless Mean I Can't Use Spring?
Not at all. Below is an example of the SJMS component using the Spring DSL:
<route id="inout.named.reply.to.producer.route"> <from uri="direct:invoke.named.reply.to.queue" /> <to uri="sjms:queue:named.reply.to.queue?namedReplyTo=my.response.queue&exchangePattern=InOut" /> </route>
It is just not using the Spring JMS APIs to provide the JMS Client container. A new container is being developed from the ground up to power SJMS. So for example, you
">Transaction Support
There is currently no support the Camel Transaction Processor nor does it support the Java Transaction API (JTA). Only internal JMS Session Transactions are supported at this time.