0

I am going through similar(http://activemq.2283324.n4.nabble.com/Sporadic-quot-Error-while-attempting-to-add-new-Connection-to-the-pool-nested-exception-is-javax-jms-td4741737.html) issues right now.

ActiveMQ version: 5.15.4 
Environment: Windows 
Karaf Version: 4.2.0 

I am using ActiveMQ and Apache Karaf with camel and pax-jms. Multiple karaf instances are using this one broker instance. My Karaf instances are installed as a service, and so is ActiveMQ as well.

This is how my config looks like:

name=db-consumer 
jms.url=tcp://localhost:61616 
jms.username=<user> 
jms.password=<password> 
type=activemq 
osgi.jndi.service.name=jms/consumer 

Time and again, with high frequency of data, I am getting the following error:

Uncategorized exception occurred during JMS processing; nested exception is javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.BindException: Address already in use: connect

Do I need to configure something specific in the broker or in the configuration to resolve this issue?

I tried pool=transx, but it starves for transx.

I saw that, there is a related post (ActiveMQ gives: "Could not connect to broker URL: tcp://localhost:61616" after around 10 000 messages) on stackoverflow, but this seems to be a problem in spring. I am looking for solution in osgi with pax-jms.

--Update 1: Added error dump--

org.springframework.jms.UncategorizedJmsException: Uncategorized exception occurred during JMS processing; nested exception is javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.BindException: Address already in use: connect
    at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:316) ~[115:org.apache.servicemix.bundles.spring-jms:4.3.14.RELEASE_1]
    at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:169) ~[115:org.apache.servicemix.bundles.spring-jms:4.3.14.RELEASE_1]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:487) ~[115:org.apache.servicemix.bundles.spring-jms:4.3.14.RELEASE_1]
    at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.send(JmsConfiguration.java:516) ~[52:org.apache.camel.camel-jms:2.20.3]
    at org.apache.camel.component.jms.JmsProducer.doSend(JmsProducer.java:440) ~[52:org.apache.camel.camel-jms:2.20.3]
    at org.apache.camel.component.jms.JmsProducer.processInOnly(JmsProducer.java:394) ~[52:org.apache.camel.camel-jms:2.20.3]
    at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:157) ~[52:org.apache.camel.camel-jms:2.20.3]
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148) ~[51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) ~[51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) ~[51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.FatalFallbackErrorHandler.process(FatalFallbackErrorHandler.java:82) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.RedeliveryErrorHandler.deliverToFailureProcessor(RedeliveryErrorHandler.java:1063) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:474) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:117) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) [51:org.apache.camel.camel-core:2.20.3]
    at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:112) [52:org.apache.camel.camel-jms:2.20.3]
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:719) [115:org.apache.servicemix.bundles.spring-jms:4.3.14.RELEASE_1]
    at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:679) [115:org.apache.servicemix.bundles.spring-jms:4.3.14.RELEASE_1]
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:649) [115:org.apache.servicemix.bundles.spring-jms:4.3.14.RELEASE_1]
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:317) [115:org.apache.servicemix.bundles.spring-jms:4.3.14.RELEASE_1]
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:255) [115:org.apache.servicemix.bundles.spring-jms:4.3.14.RELEASE_1]
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1166) [115:org.apache.servicemix.bundles.spring-jms:4.3.14.RELEASE_1]
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1158) [115:org.apache.servicemix.bundles.spring-jms:4.3.14.RELEASE_1]
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1055) [115:org.apache.servicemix.bundles.spring-jms:4.3.14.RELEASE_1]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
    at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.BindException: Address already in use: connect
    at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36) ~[?:?]
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:374) ~[?:?]
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:304) ~[?:?]
    at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:244) ~[?:?]
    at org.ops4j.pax.jms.activemq.ActiveMQConnectionFactoryFactory$1.createConnection(ActiveMQConnectionFactoryFactory.java:52) ~[?:?]
    at Proxy907e4baf_5e06_4932_b3c9_aebc6215955c.createConnection(Unknown Source) ~[?:?]
    at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:180) ~[?:?]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:474) ~[?:?]
    ... 38 more
Caused by: java.net.BindException: Address already in use: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[?:?]
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) ~[?:?]
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:?]
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:?]
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:?]
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[?:?]
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:?]
    at java.net.Socket.connect(Socket.java:589) ~[?:?]
    at org.apache.activemq.transport.tcp.TcpTransport.connect(TcpTransport.java:525) ~[?:?]
    at org.apache.activemq.transport.tcp.TcpTransport.doStart(TcpTransport.java:488) ~[?:?]
    at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:55) ~[?:?]
    at org.apache.activemq.transport.AbstractInactivityMonitor.start(AbstractInactivityMonitor.java:169) ~[?:?]
    at org.apache.activemq.transport.InactivityMonitor.start(InactivityMonitor.java:52) ~[?:?]
    at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:64) ~[?:?]
    at org.apache.activemq.transport.WireFormatNegotiator.start(WireFormatNegotiator.java:72) ~[?:?]
    at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:64) ~[?:?]
    at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:64) ~[?:?]
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:354) ~[?:?]
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:304) ~[?:?]
    at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:244) ~[?:?]
    at org.ops4j.pax.jms.activemq.ActiveMQConnectionFactoryFactory$1.createConnection(ActiveMQConnectionFactoryFactory.java:52) ~[?:?]
    at Proxy907e4baf_5e06_4932_b3c9_aebc6215955c.createConnection(Unknown Source) ~[?:?]
    at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:180) ~[?:?]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:474) ~[?:?]
    ... 38 more

Update:

To people who might encounter this issue, please remember to use connection pooling on the client side. I was using Camel Bundles. And, switching to connection pooling might not work on the fly. Restart the broker and restart the instances to see the effect. I guess, there is some kind of connection caching going on, because of which I was not able to see the changes immediately.

The pax-jms version of connection pooling config looks like:

name=db-consumer 
jms.url=tcp://localhost:61616 
jms.username=<user> 
jms.password=<password> 
type=activemq 
pool=pooledjms
osgi.jndi.service.name=jms/consumer 

I could try transx pool as well, but pooledjms was the easiest one and it works for my requirements.

cooshal
  • 758
  • 8
  • 21
  • What do you get from a `netstat -a |grep 61616` if you could [edit] your question to include the output. It looks very much like something else is binding to that port. – user3788685 May 31 '19 at 16:53
  • Hi. thank you for you reply. Actually, this error is quite tricky, because this originated from a JMS client. I believe that this has something to do with the pooled connection. Regarding the output of the command, it shows that 61616 is occupied (because I am running activemq server on that port), and that's perfectly fine. And interesting thing is, I get this error once in a while (e.g. for >500 messages) – cooshal Jun 02 '19 at 05:16
  • Hello @Cooshal, i am facing this issue, how did you fix this? – Rohit Patidar Jul 13 '21 at 06:59
  • Hello @RohitPatidar, if I remember correctly, I had switched to pax-jms based connection factory, and this somehow created issues. so, in my case, I switched to blueprint to create JMS Connection Factory https://github.com/cooshal/karaf-assembly-jms/blob/DWH-Blueprint-JMS/datasources/broker-datasource/src/main/resources/OSGI-INF/blueprint/broker-connectionfactory.xml – cooshal Jul 13 '21 at 12:28

0 Answers0