JMS listener
1. Overview
The JMS listener reads messages from a JMS destination, a queue or a topic.
This listener is a message-driven listener. This means that the arrival of a message on the destination activates the listener. The listener’s output is a ConnectMessage.
|
The content of the JMS message is put in a MessagePart of a new ConnectMessage (see MessagePart Out). If a Progress MultipartMessage is received, a ConnectMessage MultipartMessage is generated. The JMS headers are copied to the ConnectMessage headers. |
You choose between a queue or a topic with the JMS Topology attribute. The screen adjusts accordingly.
To fetch a message from a queue at a moment of your choosing, in the middle of a flow, use the JMS OnDemand Poller instead.
What happens to a message when the flow fails depends on the JMS Transaction Mode: see Acknowledging messages: JMS Transaction Mode.
2. Acknowledging messages: JMS Transaction Mode
JMS Transaction Mode decides when the broker is told that a message is done, and therefore what happens to the message when the flow fails. The mode exists for queue listeners only. A topic listener acknowledges a message as soon as it is handed to the flow, see Topic listeners.
Which mode to pick:
-
flow_transacted: failed messages must be retried, and every path of the flow ends in a producer that supports it (see Paths that need a JMS Acknowledgement). -
session_transacted: you decide per path, with a JMS Acknowledgement or a JMS Rollback. -
not_transacted: only if losing a failed message is acceptable.
The table applies to a listener with Synchronized switched off. For Synchronized, see Synchronized listeners.
| Mode | The message is acknowledged | When the flow fails | JMS Acknowledgement and JMS Rollback |
|---|---|---|---|
|
As soon as the listener has received the message, before the flow has done anything with it. |
The message is gone from the queue. It is not delivered again. Only your own error flow can keep it. |
No effect. The flow continues and the log shows a warning ( |
|
Automatically, when the final producer of the flow has sent the message, if that producer supports it. |
When the error reaches the error handling of the flow, the message is rolled back and the broker delivers it again. |
Optional on paths that end in a producer that commits; required on other paths (discard, Kafka Sender, Message Reply, …). A JMS Acknowledgement acknowledges earlier than the producer would. A JMS Rollback rolls the message back, and the producer then no longer acknowledges it. |
|
Only by a JMS Acknowledgement in the flow. |
Nothing happens by itself. The flow must roll the message back with a JMS Rollback, usually in the error flow. Without one, the message is rolled back after 5 minutes. |
Required. Every path through the flow, including discard and error flows, must end in one of them. |
|
In a transacted mode the listener keeps one of its consumer threads busy for every message that is in progress, until the message is acknowledged or rolled back. If a message is neither, for example because a filter discarded it or a service returned no message, the listener rolls it back after 5 minutes and the broker delivers it again. This waiting time cannot be changed. With the default of one Concurrent Consumers the listener processes nothing else during those 5 minutes. Make sure every path ends in an acknowledgement, a rollback or a producer that commits. |
2.1. Paths that need a JMS Acknowledgement
In flow_transacted mode the message is acknowledged by the final producer of the path, but only by these producers: AMQP Sender, AS2 Sender, Amazon SQS Sender, E-Mail Sender, File Drop, FTP Upload (FTP, FTPS and SFTP), JMS Sender, JMX Operation Invoking Producer, MQTT Sender, Null Producer, Progress OpenEdge Sender, TCP Sender and User-defined Message Sender.
A path that ends in any other producer, for example Kafka Sender, Salesforce Update Sender, Salesforce Delete Sender or Message Reply, or that ends in a filter without a producer, does not acknowledge the message. The listener waits 5 minutes, rolls the message back, and the broker delivers it again. Put a JMS Acknowledgement on such a path.
A Flow Sender only hands the message to another flow and does not acknowledge it. The final producer of that other flow does, if it is in the list above.
2.2. Error flows
-
flow_transacted: when an error reaches the error handling, the message is rolled back first, before the error flow runs. A producer at the end of the error flow does not undo that: it does not acknowledge a message that is already rolled back. So the message is delivered again even when the error flow handled the failure, for example by sending a notification. We know of no way to complete a message after its flow has failed in this mode. If the error flow must complete the message, usesession_transactedand put a JMS Acknowledgement in the error flow. -
session_transacted: nothing is rolled back automatically, and a producer at the end of the error flow does not acknowledge the message either. End the error flow with a JMS Acknowledgement if the failure is handled, or with a JMS Rollback if the message must be retried. Without either, the message is rolled back after 5 minutes.
2.3. Synchronized listeners
The mode table does not apply to a listener with Synchronized switched on. The listener itself waits for the reply of the flow, so it does not wait for a JMS Acknowledgement or JMS Rollback, the 5-minute rule does not apply and nothing is rolled back automatically. JMS Acknowledgement and JMS Rollback have no effect.
-
not_transacted: the message is acknowledged as soon as it is received, not after the reply. When the flow fails the message is lost, as without Synchronized. -
flow_transactedandsession_transacted: the message is committed when the listener has finished handling the request, after the reply has been sent. We do not guarantee that a failing flow makes the broker deliver the message again, so do not rely on redelivery with Synchronized.
2.4. Topic listeners
A topic listener has no JMS Transaction Mode: it acknowledges the message as soon as it is handed to the flow, as not_transacted does. The exception is the system property described under Operations.
3. Redelivery and the dead letter queue
In both transacted modes a message that is rolled back stays on the queue. The broker delivers it again to the listener, the flow runs again, and this repeats until the redelivery policy gives up and moves the message to the dead letter queue.
With the default connection factory of the agent (activeMQFactory, the built-in ActiveMQ broker of the agent) the redelivery policy allows 50 redeliveries, about 10 seconds apart. A message is therefore delivered up to 51 times, over about 8 minutes, before it ends up on the dead letter queue (ActiveMQ.DLQ in the built-in broker). A connection factory that you define yourself has the redelivery policy that you give it, and another broker has its own defaults, so check the redelivery settings of your broker.
For a message that must go to the dead letter queue straight away, define your own connection factory with a maximum of 0 redeliveries in <connectplaza-install-directory>/context/custom-connection-factories.xml, and select it in the Connection Factory attribute of the listener. The setting belongs to that factory only: listeners that use another factory keep its policy.
<bean id="noRedeliveryConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
<property name="redeliveryPolicy">
<bean class="org.apache.activemq.RedeliveryPolicy">
<property name="maximumRedeliveries" value="0"/>
</bean>
</property>
</bean>
Use the URL of your broker as brokerURL. The example uses the standard ActiveMQ property redeliveryPolicy. We do not ship it in the agent, so test it with your broker. Restart the agent after changing the file.
4. Things to design for, and operations
4.1. Things to design for
-
A rollback is a rollback of the message, not of what the flow already did. Whatever an earlier step has already sent or written stays sent or written, so a redelivered message can be processed more than once.
-
A message that is in progress when you turn the listener off in Control is rolled back and delivered again later, so it can be processed twice.
-
The number of messages in progress in a transacted mode is the number of Concurrent Consumers, see Concurrency.
4.2. Operations
-
The Java system property
connectplaza-jms-session-transacted=trueon the agent makes everynot_transactedlistener work assession_transacted, whatever the setting in the component. This includes non-durable topic listeners, which then need a JMS Acknowledgement or JMS Rollback as well. Aflow_transactedlistener keepsflow_transacted, and a durable topic listener is not affected. -
The standard service wrapper of the agent reads Java options from
wrapper.conf: add a linewrapper.java.additional.<n>=-Dconnectplaza-jms-session-transacted=truewith a free number and restart the agent. If you start the agent in another way, add the option there.
5. Waiting for messages: timeout and large messages
An idle listener waits for a message for the number of milliseconds in Timeout (default 60000), and then starts waiting again. It does not stop or fail after the timeout. The field is only shown when Synchronized is switched on, but the default of 60000 applies to every listener.
With Synchronized switched on, Timeout is also the time the listener waits for the reply from the flow. When no reply has arrived by then, the listener sends no reply to the requester.
Since 5.3.1 a listener in a transacted mode no longer drops a message that takes longer to arrive than Timeout, for example a large message over a slow connection.
6. Concurrency
Concurrent Consumers is the number of messages the listener can receive at the same time. Max Concurrent Consumers is the number it can grow to when messages arrive faster than they are processed, but only with not_transacted. The order of the messages is no longer guaranteed with more than one consumer.
In a transacted mode each message in progress occupies one consumer until it is acknowledged or rolled back, and the listener never works with more consumers than Concurrent Consumers: Max Concurrent Consumers has no effect there. Set Concurrent Consumers to the number of messages you want in progress at the same time.
Each JMS listener opens its own connection to the broker. Check that your broker allows enough connections.
7. Queues
In the table below, you will find an explanation of these properties.
All attributes with a * are mandatory.
All attributes with a '* ' , require at least one of these properties having been set.
|
|
8. Topics
In the table below, you will find an explanation of these properties. A topic listener has no JMS Transaction Mode: a message is acknowledged as soon as it is handed to the flow, as with not_transacted.
All attributes with a * are mandatory.
All attributes with a '* ' , require at least one of these properties having been set.
|
|
9. Adding a new broker for JMS
When you want to use a new JMS Broker within ConnectPlaza®, you need to create a new connectionfactory with the correct settings for your new JMS Broker. For instance you want to use ActiveMQ as an external Messaging broker. What to do?
Open the file
<connectplaza-install-directory>/context/custom-connection-factories.xml
and add the settings for the ActiveMQ Broker.
<bean id="amqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>tcp://localhost:61616</value>
</property>
</bean>
Change the default Connection Factory to the ID in this bean, i.e. amqConnectionFactory.
After changing the XML file, restart the ConnectPlaza® Agent.
A session cache, client id or exception listener that you set on a wrapping connection factory is ignored by JMS listeners.