JMS - Apache Artemis Source
Provided by: "Apache Software Foundation"
Support Level for this Kamelet is: "Stable"
Receives each message from a queue or a topic in an Apache ActiveMQ Artemis broker, through JMS.
Use it to process work that other applications put on a queue, such as orders or jobs, or to react to events published on a topic. For another broker that speaks AMQP 1.0, use jms-amqp-10-source.
Output: the body is text for a JMS text message, bytes for a bytes message, and a Map for a map message. The JMS properties of the message become headers, along with the JMS headers such as JMSMessageID, JMSDestination, JMSTimestamp, JMSPriority and JMSRedelivered.
Good to know: From a queue, each message is removed when it is received, even when the rest of the flow then fails, unless transacted is true or acknowledgementModeName is CLIENT_ACKNOWLEDGE: then a message whose flow failed is delivered again. Several copies of this source share the messages of a queue, and concurrentConsumers processes several messages at the same time. From a topic (destinationType set to topic), it receives only the messages sent while it is connected, unless subscriptionDurable is true: then the broker keeps the messages sent while it is stopped, under subscriptionName. A durable subscription needs clientId unless it is shared (subscriptionShared, JMS 2.0), and only one connection may use a client ID at a time. With selector, it receives only the messages whose properties and headers match the selector. It connects with no TLS unless brokerURL asks for it, and logs in with username and password when they are set. When the broker cannot be reached, it starts anyway and tries again every 5 seconds.
Configuration Options
The following table summarizes the configuration options available for the jms-apache-artemis-source Kamelet:
| Property | Name | Description | Type | Default | Example |
|---|---|---|---|---|---|
Broker URL | Required The address of the Artemis broker, as | string | tcp://localhost:61616 | ||
Queue or Topic Name | Required The name of the queue or topic to receive the messages from. | string | orders | ||
Acknowledgement Mode | When the source acknowledges each message to the broker, which then removes it from the queue. Enum values: * AUTO_ACKNOWLEDGE * CLIENT_ACKNOWLEDGE * DUPS_OK_ACKNOWLEDGE | string | |||
Client ID | The JMS client ID of the connection, which names this application to the broker. A durable subscription that is not shared needs one: the broker keeps the subscription under the client ID and | string | orders-service | ||
Concurrent Consumers | How many messages the source processes at the same time, each in a thread of its own. From a queue, more than one makes the source faster when each message takes a while, but the messages are then no longer processed in the order of the queue. On a topic, each consumer is a subscription of its own and receives every message, so each message is processed that many times, unless | integer | 5 | ||
Queue or Topic | Whether | string | queue | ||
Broker Password | The password to log in to the broker with, for the user | string | |||
Message Selector | A JMS message selector: the source receives only the messages that match it. It is a condition, in a syntax like the WHERE clause of SQL, on the JMS properties and headers of the message, not on its body, such as | string | priority > 5 | ||
Durable Subscription | Whether the subscription to a topic is durable. When it is true, the broker keeps the messages sent to the topic while this source is stopped or disconnected, and delivers them when it connects again; the broker keeps the subscription, and collects messages for it, until it is removed in the broker. Set | boolean | false | ||
Subscription Name | The name of the durable or shared subscription to a topic, under which the broker keeps the subscription. Use the same name each time the source starts, to receive the messages kept while it was stopped. Set it whenever | string | orders-audit | ||
Shared Subscription | Whether the subscription to a topic is shared: the copies of this source that use the same | boolean | false | ||
Transacted | Whether each message is received in a JMS transaction, which is committed once the rest of the flow has processed the message. When the flow fails, the transaction is rolled back and the broker delivers the message again, with the header | boolean | |||
Broker Username | The user name to log in to the broker with. Leave it empty for a broker that accepts clients without a login. | string |
Dependencies
At runtime, the jms-apache-artemis-source Kamelet relies upon the presence of the following dependencies:
-
camel:jms
-
camel:kamelet
-
mvn:org.apache.activemq:artemis-jakarta-client-all:2.57.0
Camel JBang usage
Prerequisites
-
You’ve installed JBang.
-
You have executed the following command:
jbang app install camel@apache/camel Supposing you have a file named route.yaml with this content:
- route:
from:
uri: "kamelet:jms-apache-artemis-source"
parameters:
.
.
.
steps:
- to:
uri: "kamelet:log-sink" You can now run it directly through the following command
camel run route.yaml JMS Apache Artemis Source Kamelet Description
Authentication
A broker that needs a login takes it in the username and password options. Without them, the Kamelet connects with no login.
Configuration
The JMS Apache Artemis Source Kamelet supports the following configurations:
-
Broker URL: Apache Artemis broker URL (required)
-
Destination Name: JMS destination (queue or topic) name (required)
-
Destination Type: Type of destination - queue or topic (default: queue)
-
Username and Password: the login to the broker, when it needs one
-
Durable Subscription, Shared Subscription, Subscription Name and Client ID: a durable or shared subscription to a topic (see below)
-
Message Selector: receive only the messages that match a condition on their properties and headers
-
Transacted, Acknowledgement Mode and Concurrent Consumers: delivering a message again when its flow fails, and processing several messages at the same time (see below)
Output Format
The Kamelet outputs JMS messages including message body, headers, and JMS properties. The body is text for a text message, bytes for a bytes message, and a Map for a map message.
Usage Example
- route:
from:
uri: "kamelet:jms-apache-artemis-source"
parameters:
brokerURL: "tcp://artemis.example.com:61616"
destinationName: "orders.queue"
destinationType: "queue"
steps:
- to:
uri: "kamelet:log-sink" Example with Topic Subscription
By default, the source receives only the messages published to the topic while it is connected.
- route:
from:
uri: "kamelet:jms-apache-artemis-source"
parameters:
brokerURL: "tcp://artemis.example.com:61616"
username: "artemisuser"
password: "artemispass"
destinationName: "events.topic"
destinationType: "topic"
steps:
- to:
uri: "kamelet:log-sink" Example with a Durable Topic Subscription
With subscriptionDurable set to true, the broker keeps the messages published to the topic while the source is stopped, and delivers them when it starts again. The broker keeps the subscription under the client ID and the subscription name, so use the same clientId and subscriptionName each time the source starts.
- route:
from:
uri: "kamelet:jms-apache-artemis-source"
parameters:
brokerURL: "tcp://artemis.example.com:61616"
username: "artemisuser"
password: "artemispass"
destinationName: "events.topic"
destinationType: "topic"
subscriptionDurable: true
subscriptionName: "audit"
clientId: "audit-service"
steps:
- to:
uri: "kamelet:log-sink" The JMS rules to know:
-
A durable subscription that is not shared needs a
clientId. Without one, the source starts but receives nothing, and logs that the client ID is not set. -
Only one connection may use a client ID at a time. A second copy of the source with the same
clientIdreceives nothing, and logs that the client ID is already in use. -
To run several copies of the source on one durable subscription, set
subscriptionSharedtotrueas well, and leaveclientIdempty: the copies share the messages of the topic bysubscriptionName, each message going to one of them. Shared subscriptions are part of JMS 2.0. -
The durable subscription stays on the broker, and keeps collecting messages, until it is removed in the broker.
Example with a Message Selector
The source receives only the messages that match selector, a condition on the JMS properties and headers of the message. From a queue, the other messages stay on the queue.
- route:
from:
uri: "kamelet:jms-apache-artemis-source"
parameters:
brokerURL: "tcp://artemis.example.com:61616"
destinationName: "orders.queue"
selector: "priority > 5"
steps:
- to:
uri: "kamelet:log-sink" Redelivery when the flow fails
By default, the source removes each message from the queue when it receives it, so a message whose flow fails is lost. With transacted set to true, each message is received in a transaction that is committed only once the flow has processed it. When the flow fails, the transaction is rolled back and the broker delivers the message again, with the header JMSRedelivered set to true.
After 10 attempts, the default of the broker (max-delivery-attempts), Artemis moves the message to the dead letter queue, DLQ by default.
concurrentConsumers processes several messages of the queue at the same time, each in a thread of its own; the messages are then no longer processed in the order of the queue.
- route:
from:
uri: "kamelet:jms-apache-artemis-source"
parameters:
brokerURL: "tcp://artemis.example.com:61616"
destinationName: "orders.queue"
transacted: true
concurrentConsumers: 5
steps:
- to:
uri: "kamelet:log-sink" acknowledgementModeName set to CLIENT_ACKNOWLEDGE also delivers a message again when its flow fails, without a transaction. DUPS_OK_ACKNOWLEDGE acknowledges the messages in batches: it is faster, but the messages processed since the last batch are delivered again after a crash.