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:

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

not_transacted (default)

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 (Message or Session is null, cannot ack or cannot nack).

flow_transacted

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.

session_transacted

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, use session_transacted and 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_transacted and session_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=true on the agent makes every not_transacted listener work as session_transacted, whatever the setting in the component. This includes non-durable topic listeners, which then need a JMS Acknowledgement or JMS Rollback as well. A flow_transacted listener keeps flow_transacted, and a durable topic listener is not affected.

  • The standard service wrapper of the agent reads Java options from wrapper.conf: add a line wrapper.java.additional.<n>=-Dconnectplaza-jms-session-transacted=true with 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.

The JMS listener properties with queue topology
Attribute Description

Name*

By default, we fill this out with the technical tag, followed by a serial number. Changing the name is optional.

Enabled

Set this value to true, if you want this consumer to be enabled.

Consumer autostart

The listener is started at startup of the interface.

JMS Topology

Here you can choose between Queue or Topic. The screen will adjust accordingly.

Request Queue Name***

Name of queue to receive from.

Reply Queue Name

Default queue to send the reply to if Synchronized is true and the received message has no JMSReplyTo header. Only shown when Synchronized is true.

Synchronized

Defines the listener as request-response (true) or fire-and-forget (false). The default is false. When the synchronized mode is used, you must use a Message Reply in the Producer. See Synchronized listeners.

Timeout

Time in milliseconds the listener waits for a message, and when Synchronized is true also for the reply of the flow. The default is 60000. See Waiting for messages: timeout and large messages. Only shown when Synchronized is true.

MessagePart Out

Name of the MessagePart in a ConnectMessage where the content of the message is stored. Not applicable when receiving a Progress Multipart.

Connection Factory

Name of the connection factory to use. The default jmsConnectionFactory uses the factory named in property connect.connectionfactory.name in connectplaza-agent.properties, by default activeMQFactory, the built-in ActiveMQ broker of the agent.

Concurrent Consumers

Number of consumers that is always active. The default value is 1. See Concurrency.

Max Concurrent Consumers

Maximum number of consumers. The default value is 1. With not_transacted and a value higher than Concurrent Consumers, the listener starts extra consumers while many messages arrive, and stops them again when the load goes down. No effect in a transacted mode, see Concurrency.

JMS Transaction Mode

not_transacted (default), flow_transacted or session_transacted. See Acknowledging messages: JMS Transaction Mode.

Description

Description of the specific consumer. This is for documentation purposes.

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.

The JMS listener properties with topic topology
Attribute Description

Name*

By default, we fill this out with the technical tag, followed by a serial number. Changing the name is optional.

Enabled

Set this value to true, if you want this consumer to be enabled.

Consumer autostart

The listener is started at startup of the interface.

JMS Topology

Here you can choose between Queue or Topic. The screen will adjust accordingly.

Request Topic Name***

Name of topic to receive from.

Reply Topic Name

Default topic to send the reply to if Synchronized is true and the received message has no JMSReplyTo header. Only shown when Synchronized is true.

Durable Topic

The subscription is durable if the value is true. The default is false. A durable subscription is kept while the listener is turned off.

Durable Subscription Name

Name of the subscription in case of a durable subscription.

Synchronized

Defines the listener as request-response (true) or fire-and-forget (false). The default is false. When the synchronized mode is used, you must use a Message Reply in the Producer.

Timeout

Time in milliseconds the listener waits for a message, and when Synchronized is true also for the reply of the flow. The default is 60000. Only shown when Synchronized is true.

MessagePart Out

Name of the MessagePart in a ConnectMessage where the content of the message is stored. Not applicable when receiving a Progress Multipart.

Connection Factory

Name of the connection factory to use. The default jmsConnectionFactory uses the factory named in property connect.connectionfactory.name in connectplaza-agent.properties, by default activeMQFactory, the built-in ActiveMQ broker of the agent.

Concurrent Consumers

Number of consumers that is always active. The default value is 1. See Concurrency.

Max Concurrent Consumers

Maximum number of consumers. The default value is 1. See the table for queues.

Description

Description of the specific consumer. This is for documentation purposes.

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.