jms,spring-jms , Get responses based on corretionID from IBM MQ for multi-thread scenario

Get responses based on corretionID from IBM MQ for multi-thread scenario


Tag: jms,spring-jms

My requirement is that:

I have an IBM MQ which is shared across 20 servers and runs the JMS client. Now there will be a specific message in the queue which is intended for a particular thread. The thread need to use a correlationID to fetch the message from all the messages in the MQ.

When I am using onMessage() it is uncertain which thread will Listen to the message. Suppose server-1 is waiting for the message but server-15 listens it. Server-1 gets eventually timed out even though there was a message intended for the thread in server-1.

Please suggest how we are going to handle this scenario without introducing major performance issue.


Use a MessageSelector on the listener container(s). If the correlationId is in the standard JMSCorrelationID header the selector would be JMSCorrelationID=foo to receive all foo messages.


JMS Prefetch + Cached Consumers + Stuck Messages

I am trying to get JMS Consumers to work towards an ActiveMQ server however I am running into some issues which solution seem to just cause more problems. I am using Spring's DMLC (cacheLeve set to CACHE_CONNECTION) together with a CachingConnectionFactory (cachingConsumers set to true) wrapping Activemq's own ConnectionFactory in...

Valid “protocols” for HornetQ

I have some code like this for connecting to HornetQ. Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); properties.put(Context.PROVIDER_URL, "remote://"); properties.put(Context.SECURITY_PRINCIPAL, "user"); properties.put(Context.SECURITY_CREDENTIALS, "pwd"); ConnectionFactory connectionFactory = null; Destination destination = null; try { Context context = new InitialContext(properties); I inherited this, and am trying to get a...

How to set Content-Type header for JMS message

We have a Java application that sends JMS message via IBM WebSphere MQ. The consumer application requires the message content type to be set to "application/json". How can I go about doing it? I've checked through a few references and it seems I can set extra header via method "setStringProperty(headerKey,...

Message selector options JMSCorrelationID or simple string as a JMS property

Which message selector option is good ? JMSCorrelationID or simple string as a JMS property to selectively fetch messages from queue ? I believe, in term of performance they are same. Producer side using string property: message = session.CreateTextMessage(msg); message.setString("myfilter", "abc"); producer.sent(message); Producer side using JMSCorrelation ID : message =...

Setting up ActiveMQ bridge to connect to different implementations of MOM

I would like to deploy ActiveMQ in order to connect and communicate with other MOM implementations of jms such as WebsphereMQ, Tibco EMS, Oracle WebLogic JMS etc. As far as I have researched online this seems to be possible by building a so-called bridge on top of activemq that will...

Timeouts in camel

I'm using the split-aggregate functionality in Camel to split some work up amongst some JMS clients. The Camel route is defined (using groovy) as follows: from("vm:getQuotes") .split(new MethodCallExpression("requestSplitter", "splitAmongstBots"), new ArrayListAggregationStrategy()) .to("jms:queue:quoteRequests?requestTimeout=${responseTimeout}s") .unmarshal().json(JsonLibrary.Jackson) .end() The JMS clients can take between approx 15 and 90 seconds to process the tasks. I'm...

Not able to send message to Solace JMS Queue

I need to push message to Solace JMS queue Webpshere but I am getting below error during send message. I have also increase message listener size but not solved problem. Error: 503: Spool Over Quota. Message VPN limit exceeded Caused by: com.solacesystems.jcsmp.JCSMPErrorResponseException: 503: Spool Over Quota. Message VPN limit exceeded...

JMS QueueConnectionFactory vs ConnectionFactory

My question is about the use of the following 2 factories: ConnectionFactory QueueConnectionFactory At the moment I just use a ConnectionFactory to initialize everything: Connection conn = factory.createConnection(user, pw); Session session = conn.createSession() Destination dest = session.createQueue('xyz') ... If I understand correctly, the QueueConnectionFactory works pretty much the same way....

How to Produce from MQTT and consume as MQTT and JMS in ActiveMQ

I have a setup where messages are produced as MQTT to ActiveMQ. I have two consumers one as JMS and another MQTT. When I am publishing message as JMS Message to the topic "foo", I am receiving the messages at both JMS and MQTT consumers, but when I am publishing...

Publisher should wait till broker is available

I have a simple publisher, which sends messages to a queue. <int:channel id="publishChannel"/> <int-jms:outbound-channel-adapter channel="publishChannel" destination="testQueue" session-transacted="true"/> @Publisher(channel = "publishChannel") public String sendMessage (String text) { return text; } If the broker crashes, the publisher throws an MessageHandlingException. Is it possible to block the publisher, till the broker is available...

Does it make a sens to use JMS without Message orineted middleware?

I'm new to JMS and now trying to integrate it with my applications. I've decided to use apachemq jars at the client side. So, if I avoid the communication through the message broker ApacheMQ and communicate between the parts of the application directly, will it make a sense? Is the...

This method is not applicable inside the app server when trying to set a listener for a JMS queue

I am trying JMS 2.0 so I can decide if it is worth applying in my project. I could successfully create a send/receive application. Now I would like to have listeners that will receive the message as soon as it is available on the queue (my final goal is to...

Creating JMS topic publisher returns 2035 unauthorized in WMQ

I am having a ongoing problem trying to create a topic publisher from seemingly simple java code. My WMQ is administered separately in the company so I have no direct control of it. I try to connect to the topic by creating a TopicConnection, then a TopicSession and then a...

Understanding the JMS communication schema by example

Going through the JMS Oracle tutorial, I faced the following schema: There was also metnioned that the JMS application basically composed of the parts: JMS provider JMS clients Messages Administered objects I'd like to understand that communication schema by a concrete example. Assume that we have two web applications running...

JMS Broker receives the message as null

I have a C++ component which passes message to JMS broker via tcp using ActiveMQ. My broker is written in JAVA. I want these two to communicate; to C++ component send messages to the JAVA broker. On C++ side what I am doing is creating a message (using protocol buffer),...

Intercept incoming JMS messages to ActiveMQ, reject/approve based on rules

Is there a feature in ActiveMQ, perhaps with Camel, to do the following? intercept incoming message at the broker validate headers and/or body based on arbitrary rules throw exception to sender if message not validated, or.. reroute invalid messages to 'rejection' queue ...

What does vm prefix mean in the address line?

I'm going through the Apache ActiveMQ example and faced the vm prefix as follows: ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); What does that mean? By the way, when I connect to the mesasge broker I basically use an address like tcp://localhost:61616....

Write a Java Program to connect to HornetQ Messaging Service in Jboss EAP 6.3?

I am using Jboss EAP 6.3 and need to use Messaging facility. I have worked in Jboss 4x, where we can make connection easily using following code: public static final String PROVIDER_URL = "jnp://localhost:5445"; public static final String JNP_INTERFACES = "org.jboss.naming:org.jnp.interfaces"; public static final String INITIAL_CONTEXT_FACTORY = "org.jnp.interfaces.NamingContextFactory"; private static...

Error while setting targetConnectionFactory in UserCredentialsConnectionFactoryAdapter Spring 4

We are receiving a compilation error in the following code, while trying to set the targetConnectionFactory. According to the example given in Spring 4 documentation for UserCredentialsConnectionFactoryAdapter, the setTargetConnectionFactory() method takes the object of JndiObjectFactoryBean as an argument. But, looks like the JndiObjectFactoryBean hasn't implemented the 'ConnectionFactory' interface, which is...

jms selector expression in Mule is not working

<flow name="readqueueFlow1" doc:name="readqueueFlow1" > <jms:inbound-endpoint queue="MyTestQueue" connector-ref="Active_MQ-Priority" doc:name="JMS"> <jms:selector expression="JMSCorrelationID=’353’" /> </jms:inbound-endpoint> </flow> Its working but when i try to use the below one its not deploying <!-- When we don't provide single quote it is failing in deployment --> <jms:selector expression="JMSCorrelationID='#[flowVars.reqId]'" /> <!-- Payload contains reqId, when we provide...

How to create a subscription on the fly in a IBM MQ cluster?

When i use this code as subscriber: MQTopic QMsSubscription = qm.accessTopic("qmstop", "", CMQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, CMQC.MQSO_CREATE); MQMessage recvQMsMsg = new MQMessage(); MQGetMessageOptions gmo = new MQGetMessageOptions(); gmo.options = MQConstants.MQGMO_WAIT; gmo.waitInterval = MQConstants.MQWI_UNLIMITED; QMsSubscription.get(recvQMsMsg, gmo); and this code for publisher: MQTopic QMsPublisher = qm.accessTopic("qmstop", "", CMQC.MQTOPIC_OPEN_AS_PUBLICATION, CMQC.MQOO_OUTPUT); MQMessage sendQMsMsg = new MQMessage();...

JMS Message Selector does not work

I have a requirement to filter message based on the Message selector but it seems the consumer with messageSelector is not filtering any message. I have written below code ActiveMQUtil import org.apache.activemq.ActiveMQConnectionFactory; import javax.jms.*; public class ActiveMQUtil { private ConnectionFactory connectionFactory = null; private Connection connection =null; private Session session...

Automatically restore connection to the main queue when server is up again

I have a master MQ and a slave MQ. If the master MQ goes down, can I send the messages through the slave MQ using a message driven bean ? Also after my master MQ is up again can I reconnect the line automatically without restarting the JVM ?

JMS - How to correctly implement message receiver with explicit acknowledge?

The JMS API is driving me to the point of a mental breakdown.. What is the correct way to poll messages of a jms queue and explicitly acknowledge that each message has been processed correctly? Should I create a "transacted session" and which acknowledge mode is the correct one in...

JMS Translation Bundle does not extract keys from controllers in Symfony2 - getTranslationMessages()

I am using JMS Translation Bundle in my Symfony 2 project. All translations in the twig files are working great. If I write new keys that need to be translated and run the extract command from command line they get extracted and I can then set appropriate values. My question...

JMS selector strange behaviour

In JMS consider the following pseudo-code: Sender: QueueSender qs = session.createSender(queue); int i = 0; while(i < 10) { TextMessage msg = session.createTextMessage(); msg.setText(""+i); msg.setIntProperty("value", i); qs.send(msg); i++; } Receiver: String sel = "value >2"; QueueReceiver qr = session.createReceiver(q,sel); while(true) { TextMessage tm = (TextMessage) qr.receive(); System.out.println(tm.getText); } I would...

Concurrent message consumption in ActiveMQ

I use a ActiveMQServer as a broker. import java.util.HashMap; import java.util.HashSet; import java.util.Map; import org.apache.activemq.api.core.TransportConfiguration; import org.apache.activemq.core.config.Configuration; import org.apache.activemq.core.config.impl.ConfigurationImpl; import org.apache.activemq.core.remoting.impl.netty.NettyAcceptorFactory; import org.apache.activemq.core.server.ActiveMQServer; import org.apache.activemq.core.server.ActiveMQServers; public class Server { public static void...

JEE7 + WildFly (HornetQ) - Pause queue from application

We are using WildFly + HornetQ as our application server and JMS message queue, and have the requirement to be able to pause/resume queues from the application. Is this possible?

ActiveMQ http connection error

I am trying to connect my java client application to ActiveMQ over http, but keep getting an error: (complete error at the bottom) javax.jms.JMSException: Could not post command: ProducerInfo No such field org.apache.activemq.command.ProducerInfo.sentCount Also, there is connection to ActiveMQ, because the server also produces an error: (complete error at the...

Connecting remote JBoss-eap-6.2 to pass message in java

Code runs without any problem up to creating connection factory but it cannot create topic connection. When creating topic connection it throws following exception.(My code is for creating publisher and subscriber) Here is the terminal output I received, Jun 03, 2015 10:51:55 AM org.xnio.Xnio <clinit> INFO: XNIO Version 3.0.7.GA-redhat-1 Jun...

Apache Kafka is JMS api?

Apache Kafka is not a JMS implementation? I using JMS+AMQ in my application and emigration to Apache Kafka, i have to change all JMS codes?...

Spring Integration with JMS + ActiveMQ: Messages remain in JDBC Message Store after reconnect

I'm trying to configure JMS with Spring Integration and an ActiveMQ Message Broker. My outbound channel should be backed by a JDBC Message Store to prevent data loss e.g. the broker or my application goes offline. My configuration seems to work so far, however the JDBC Message Store does not...

JMS session thread implications

What does it mean that : A Session object is a single-threaded context for producing and consuming messages Why does Session extends Runnable? Does that imply that when we create a new session object, a new application level thread is always started? Please I need help on understanding this....

Remote JMS communication works, EJB communication fails

I'm currently introducing myself into Java EE, especially into how to use EJB and JMS. The Issue in a Nutshell I have a local client and a remote server in the internet. JMS communication works fine, EJB communication doesn't. Either communication succeeds in my local network. The Issue in More...

Close JMS session and connection after message received

I have a stateful session bean where I send and receive JMS messages. All the connection setup is handled manually, so the bean is holding instances of javax.jms.connection and javax.jms.session. The bean also implements MessageListener to be able receive messages. Now, when I send a message, I create a temporary...

Returning string from jms

I am writing a stand alone main method which invokes a producer (to push data into a queue), and then invokes a consumer which keeps listening to the topic. I have overridden the onMessage and I am able to get the message from the queue, but I am not able...

@JmsListener usage for publish-subscribe topic

I am trying to create example for publish-subscribe based on @JmsListener annotation: Relevant code snippets: @Slf4j @SpringBootApplication @EnableScheduling public class JmsPublishSubscribeApplication { public static void main(String[] args) throws InterruptedException {, args); } @Bean public ActiveMQTopic simpleTopic() { return new ActiveMQTopic("simpleTopic"); } } @Component public class...

MQ connection throwing null pointer during context.lookup in tomcat

I am trying to connect to MQ using JNDI lookup defined in context.xml of tomcat. While starting the application, i am getting a NamingException and a NullPointer in FFDC. Below is what logged. I am not able to make out what is wrong. Any indication on how to debug this...

Handle exceptions caused by message-converter on Message Driven Inbound Channel Adapter

In the configuration below I have a message-driven-channel-adapter with a message-converter so the service-activator is invoked with the converted payload. <int-jms:message-driven-channel-adapter id="myConsumerChannelAdapter" connection-factory="connectionFactory" destination="input_queue" channel="input_channel" error-channel="errorChannel" message-converter="messageConverter" header-mapper="jmsHeaderMapper" acknowledge="client" max-concurrent-consumers="10"/> <int:service-activator input-channel="input_channel"...

Sending Message to QueueChannel

My knowledge of JMS is extremely weak so please bear with me. I am trying to send a simple message to a Queue Message Channel. @Autowired private MessageChannel myChannel = null; @Test public void testRecieveMethod() { Message m = ((QueueChannel)myChannel).receive(); System.out.println("HELLO"); } The program hangs like its supposed to but...

messagebased RPC with topic

A simple message-based RPC is very easy to create. The server side exports the service, the client side uses a proxy. What is the best way, to make the same thing with multiple repliers? I want to send a request from a client. Then the client waits while all (maybe...

How can I ask a JMS server to resend the message when an exception occurs in a JMS listener defined with the @JmsListener annotation?

I have been writing a JMS listener in a Springboot application. I used two ways: 1) Defines a a bean which is SimpleMessageListenerContainer like this: @Bean SimpleMessageListenerContainer getMyMessageListenerContainer(ConnectionFactory connectionFactory) { MessageListenerAdapter messageListener = new MessageListenerAdapter(myService); messageListener.setDefaultListenerMethod("myMethodListener"); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setMessageListener(messageListener);...

How to handle transaction rollback with JMS and JPA in a Java EE environment?

The default rollback behavior for a CMT MDB is to return the message to the destination so it may be processed again. Is it possible to avoid redelivering a message handled by a managed MDB even if the the transaction is rolled back? (Or maybe configure the acknowledgement behavior handled...

Spring-boot app displaying JMS messages on WebPage via WebSocket

I have an urgent need for a simple web-app in spring-boot that listens for messages on a JMS queue and when arriving it should appear on a webpage via WebSocket. I need a solution for this very soon in a demonstration. I have searched for examples and found several individual;...

WSO2 Message Broker not receiving message

i followed the official documentation dealing with the integration between WSO2 ESB and WSO2 MB. On my WSO2 ESB 8.1.0 i wrote a simple proxy like this: <?xml version="1.0" encoding="UTF-8"?> <proxy xmlns="" name="jobReplicaFeed" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence> <log level="full"/> <send> <endpoint key="ReplicaFeedEndpoint"/> </send>...