Refresh JMS Connection in Spring Project using ActiveMQ - spring

I have a Spring project in which I am using Apache Camel and ActiveMQ as message broker. When I started my Java application which receives from the topic and when the broker is not started it gives an error (which is valid), but even after starting the broker JMS connection is not refreshed.
I tried the same case in the Spring Boot app and it automatically refreshed the JMS connection. Something needs to be handled manually in Spring but not sure of that thing.
This is the error from my Spring app:
org.apache.camel.component.jms.DefaultJmsMessageListenerContainer: Could not refresh JMS Connection for destination 'test.events.topic' - retrying using FixedBackOff{interval=5000, currentAttempts=1, maxAttempts=unlimited}. Cause: Could not connect to broker URL: tcp://activemq:61616. Reason: java.net.UnknownHostException: activemq
This is what the Spring Boot application reports:
Successfully refreshed JMS Connection
Below is the broker configuration:
broker:
host: localhost
port: 61616
protocol: tcp
endpoint: ${broker.protocol}://${broker.host}:${broker.port}
url: failover:(${broker.endpoint}?wireFormat.maxInactivityDurationInitalDelay=30000)?timeout=3000&jms.useCompression=true&startupMaxReconnectAttempts=0&jms.redeliveryPolicy.maximumRedeliveries=${maxConsumers}

Related

Camel JMS : connection refresh not working (IBM MQ)

I'm using the following endpoint :
jms:queue:MY_JMS_QUEUE?transacted=true&recoveryInterval=10000&testConnectionOnStartup=true
Everything works well but whenever the MQ connection is lost (due to IBM MQ server restart), the connection refresh does not work.
In my logs i have that :
ERROR [c.c.j.DefaultJmsMessageListenerContainer] []] Could not refresh JMS Connection for destination 'MY_JMS_QUEUE' - retrying using FixedBackOff{interval=10000, currentAttempts=0, maxAttempts=unlimited}. Cause: JMSWMQ0018: Failed to connect to queue manager 'xxx' with connection mode 'Client' ......('MQRC_Q_MGR_NOT_AVAILABLE')
And nothing else, i was expecting to have the same error messages multiples times with currentAttempts=1 then 2... until the MQ is back.
I checked the documentation but i don't see anything else. My configuration:
Camel version : 3.11.3
Java: 11.0.8
Spring boot : 2.5.2
As your connection mode is "Client" you can give the MQ automatic JMS client reconnection feature a try. You would need to configure the "ClientReconnectOptions" in the connection factory definition.

IBM MQ JMS connection not established from eclipse spring boot

I have been getting the issue of JMS connection refreshed from a few days.
Previously I was able to connect to the MQ and the same spring boot java code was working fine.
Now, the war file I build and deploy in the IBM Websphere also works. But it doesnt connect from Eclipse IDE. New to IBM MQ. Please help.
Setup of JMS message listener invoker failed for destination 'testq_OUT' - trying to recover. Cause: JMSCC0008: This connection is closed.
2022-03-10 14:44:28,659 INFO org.springframework.jms.connection.SingleConnectionFactory [DefaultMessageListenerContainer-1] Established shared JMS Connection: com.ibm.mq.jms.MQQueueConnection#3d803c95
2022-03-10 14:44:28,659 INFO org.springframework.jms.listener.DefaultMessageListenerContainer [DefaultMessageListenerContainer-1] Successfully refreshed JMS Connection
2022-03-10 14:44:34,767 WARN org.springframework.jms.listener.DefaultMessageListenerContainer [DefaultMessageListenerContainer-2] Setup of JMS message listener invoker failed for destination 'testq_OUT' - trying to recover. Cause: com.ibm.mq.MQException.<init>(Ljava/lang/String;Ljava/lang/String;II)V
2022-03-10 14:44:34,768 INFO org.springframework.jms.listener.DefaultMessageListenerContainer [DefaultMessageListenerContainer-2] Successfully refreshed JMS Connection
2022-03-10 14:44:40,788 WARN org.springframework.jms.listener.DefaultMessageListenerContainer [DefaultMessageListenerContainer-3] Setup of JMS message listener invoker failed for destination 'testq_OUT' - trying to recover. Cause: com.ibm.mq.MQException.<init>(Ljava/lang/String;Ljava/lang/String;II)V
2022-03-10 14:44:40,788 INFO org.springframework.jms.listener.DefaultMessageListenerContainer [DefaultMessageListenerContainer-3] Successfully refreshed JMS Connection
Please check the stack trace here
I found that some jms jars are not picked up from maven repo by the ide. so tried adding them on the build path and this works!

Can't turn of auto create function in embedded ActiveMQ

I would like to use ActiveMQ in my Spring Boot application. During debugging I have found out following error:
org.apache.activemq.broker.BrokerService : Failed to start Apache ActiveMQ (localhost, null)javax.management.InstanceAlreadyExistsException: org.apache.activemq:type=Broker,brokerName=localhost`
Seems like broker is created upon creation of the first connection, according to ActiveMQ's documentation. Is is possible to turn off auto-creation by setting the create property on the VM Transport to false, e.g.:
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?create=false");
When I tried this solution I got following error:
DefaultJmsMessageListenerContainer : Could not refresh JMS Connection for destination 'test' - retrying using FixedBackOff{interval=5000, currentAttempts=364, maxAttempts=unlimited}. Cause: Could not create Transport. Reason: java.io.IOException: Broker named 'localhost' does not exist.
Now I think the broker is not creating at all or this process is pending. Did anyone have a similar issue? If so how did you resolve it?
ActiveMQ's vm transport optionally creates a broker, or connects to a running broker.
Sounds like you are missing a step in your application boot-up plan. Either you need:
A component to startup the broker
Designate one of the connection factories to start the broker using the vm transport:
Designated broker startup connection factory:
vm://localhost?create=true
All other connection factories:
vm://localhost?create=false

Spring 5 JMS clientID=myapp.Topic was already set into another connection

I am using Spring Boot 2.2.1 (w/ Spring 5) to kick off my server with Spring JmsTemplate (HornetQ) connections. Every ~10s an ERROR is logged,
2020-01-17 18:00:49,091 [DefaultMessageListenerContainer-1] ERROR listener.DefaultMessageListenerContainer - Could not refresh JMS Connection for destination 'a.Topic' - retrying using FixedBackOff{interval=5000, currentAttempts=2, maxAttempts=unlimited}. Cause: clientID=myapp.Topic was already set into another connection
Did I accidentally create another client using the same id and compete for the connection/topic? Or something else I am not aware of.
Did I accidentally create another client using the same id and compete for the connection/topic?
Yes. According to the error message you're receiving you did.

SimpleMessageListenerContainer failed to reconnect on ems broker failover

I have 2 jms listener applications one application uses DefaultMessageListenerContainerand other application uses SimpleMessageListenerContainer
The application with DefaultMessageListenerContainer was able to reconnect on EMS broker failover, here is the log
Setup of JMS message listener invoker failed for destination 'SOME.TOPIC.T' - trying to recover. Cause: Connection is closed
Could not refresh JMS Connection for destination 'SOME.TOPIC.T' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: Failed to connect to any server at: tcp://localhost:8285,tcp://localhost:8286
Could not refresh JMS Connection for destination 'SOME.TOPIC.T' - retrying using FixedBackOff{interval=5000, currentAttempts=1, maxAttempts=unlimited}. Cause: Failed to connect to any server at: tcp://localhost:8285,tcp://localhost:8286
The application with SimpleMessageListenerContainer was not able to reconnect on EMS broker failover, here is the log
[TIBCO EMS TCPLink Reader (Server-109365)] INFO org.springframework.jms.listener.SimpleMessageListenerContainer - Trying to recover from JMS Connection exception: javax.jms.JMSException: Connection has been terminated
[TIBCO EMS TCPLink Reader (Server-109366)] ERROR org.springframework.jms.listener.SimpleMessageListenerContainer - Encountered non-recoverable JMSException
javax.jms.JMSException: Connection has been terminated
at com.tibco.tibjms.Tibjmsx.buildException(Tibjmsx.java:659) ~[tibjms-8.3.0.jar!/:?]
at com.tibco.tibjms.TibjmsConnection._invokeOnExceptionCallback(TibjmsConnection.java:2118) [tibjms-8.3.0.jar!/:?]
at com.tibco.tibjms.TibjmsConnection._onDisconnected(TibjmsConnection.java:2487) [tibjms-8.3.0.jar!/:?]
at com.tibco.tibjms.TibjmsConnection$ServerLinkEventHandler.onEventDisconnected(TibjmsConnection.java:367) [tibjms-8.3.0.jar!/:?]
at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.work(TibjmsxLinkTcp.java:328) [tibjms-8.3.0.jar!/:?]
at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.run(TibjmsxLinkTcp.java:259) [tibjms-8.3.0.jar!/:?]
Both are connected to same broker instance, how to make the SimpleMessageListenerContainer listener to reconnect on JMS Exceptions?
The simple container is ... er ... Simple.
It makes only one attempt to recover the connection.
The default container is more sophisticated and configured with a BackOff (default every 5 seconds for infinite attempts).
Use a default container if you need that sophistication, but it needs to be transactional to avoid the possibility of message loss - see the javadocs.

Resources