2.59. JMS


Send and receive messages to/from a JMS Queue or Topic.

2.59.1. What’s inside

Refer to the above link for usage and configuration details.

2.59.2. Maven coordinates

Create a new project with this extension on code.camel.redhat.com

Or add the coordinates to your existing project:

<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-jms</artifactId>
</dependency>

2.59.3. Usage

2.59.3.1. Message mapping with org.w3c.dom.Node

The Camel JMS component supports message mapping between jakarta.jms.Message and org.apache.camel.Message. When wanting to convert a Camel message body type of org.w3c.dom.Node, you must ensure that the camel-quarkus-xml-jaxp extension is present on the classpath.

2.59.3.2. Native mode support for jakarta.jms.ObjectMessage

When sending JMS message payloads as jakarta.jms.ObjectMessage, you must annotate the relevant classes to be registered for serialization with @RegisterForReflection(serialization = true). Note that this extension automatically sets quarkus.camel.native.reflection.serialization-enabled = true for you. Refer to the native mode user guide for more information.

注意

Connection pooling is a Technical Preview feature in this release of {project-name}.

To use connection pooling in the camel-quarkus-jms components, you must add io.quarkiverse.artemis:quarkus-artemis and io.quarkiverse.messaginghub:quarkus-pooled-jms to your pom.xml and set the following configuration:

quarkus.pooled-jms.max-connections = 8

You can use the quarkus-pooled-jms extension to get pooling and XA support for JMS connections. Refer to the quarkus-pooled-jms extension documentation for more information. Currently, it can work with quarkus-artemis-jms, quarkus-qpid-jms and ibmmq-client. Just add the dependency to your pom.xml:

<dependency>
    <groupId>io.quarkiverse.messaginghub</groupId>
    <artifactId>quarkus-pooled-jms</artifactId>
</dependency>

Pooling is enabled by default.

注意

clientID and durableSubscriptionName are not supported in pooling connections. If setClientID is called on a reused connection from the pool, an IllegalStateException will be thrown. You will get some error messages such like Cause: setClientID can only be called directly after the connection is created

To enable XA, you need to add quarkus-narayana-jta extension:

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-narayana-jta</artifactId>
</dependency>

and add the following configuration to your application.properties:

quarkus.pooled-jms.transaction=xa
quarkus.transaction-manager.enable-recovery=true

XA support is only available with quarkus-artemis-jms and ibmmq-client. Also We highly recommend to enable transaction recovery.

Since there is no quarkus extension for ibmmq-client currently, you need to create a custom ConnectionFactory and wrap it by yourself. Here is an example:

@Produces
public ConnectionFactory createXAConnectionFactory(PooledJmsWrapper wrapper) {
    MQXAConnectionFactory mq = new MQXAConnectionFactory();
    try {
        mq.setHostName(ConfigProvider.getConfig().getValue("ibm.mq.host", String.class));
        mq.setPort(ConfigProvider.getConfig().getValue("ibm.mq.port", Integer.class));
        mq.setChannel(ConfigProvider.getConfig().getValue("ibm.mq.channel", String.class));
        mq.setQueueManager(ConfigProvider.getConfig().getValue("ibm.mq.queueManagerName", String.class));
        mq.setTransportType(WMQConstants.WMQ_CM_CLIENT);
        mq.setStringProperty(WMQConstants.USERID,
            ConfigProvider.getConfig().getValue("ibm.mq.user", String.class));
        mq.setStringProperty(WMQConstants.PASSWORD,
            ConfigProvider.getConfig().getValue("ibm.mq.password", String.class));
    } catch (Exception e) {
        throw new RuntimeException("Unable to create new IBM MQ connection factory", e);
    }
    return wrapper.wrapConnectionFactory(mq);
}
注意

If you use ibmmq-client to consume messages and enable XA, you need to configure TransactionManager in the camel route like this:

@Inject
TransactionManager transactionManager;

@Override
public void configure() throws Exception {
    from("jms:queue:DEV.QUEUE.XA?transactionManager=#jtaTransactionManager");
}

@Named("jtaTransactionManager")
public PlatformTransactionManager getTransactionManager() {
    return new JtaTransactionManager(transactionManager);
}

Otherwise, you will get an exception like MQRC_SYNCPOINT_NOT_AVAILABLE.

注意

When you are using ibmmq-client and rollback a transaction, there will be a WARN message like:

WARN  [com.arj.ats.jta] (executor-thread-1) ARJUNA016045: attempted rollback of < formatId=131077, gtrid_length=35, bqual_length=36, tx_uid=0:ffffc0a86510:aed3:650915d7:16, node_name=quarkus, branch_uid=0:ffffc0a86510:aed3:650915d7:1f, subordinatenodename=null, eis_name=0 > (com.ibm.mq.jmqi.JmqiXAResource@79786dde) failed with exception code XAException.XAER_NOTA: javax.transaction.xa.XAException: The method 'xa_rollback' has failed with errorCode '-4'.
it may be ignored and can be assumed that MQ has discarded the transaction's work. Refer to https://access.redhat.com/solutions/1250743[Red Hat Knowledgebase] for more information.

2.59.4. transferException option in native mode

To use the transferException option in native mode, you must enable support for object serialization. Refer to the native mode user guide for more information.

You will also need to enable serialization for the exception classes that you intend to serialize. For example.

@RegisterForReflection(targets = { IllegalStateException.class, MyCustomException.class }, serialization = true)
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部