3
votes

I have following setting in my spring context file.

<bean id="amqPowerConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <constructor-arg index="0" value="${power.messagebrokerurl}"/>
</bean>

<bean id="powerConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
    <constructor-arg ref="amqPowerConnectionFactory"/>
</bean>

<bean id="powerEventQueue" class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg value="PowerEventQueue"/>
</bean>

<bean id="timeSeriesChangesContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="powerConnectionFactory"/>
    <property name="destination" ref="powerEventQueue"/>
    <property name="messageListener" ref="timeSeriesDataAdapter"/>
    <property name="recoveryInterval" value="5000"/>
</bean>

<bean id="timeSeriesDataAdapter" class="com.sungard.energy.aligne.aligneweb.assetManagement.TimeSeriesMessageAdapter">
    <property name="queueName"><value>"PowerEventQueue"</value></property>
    <property name="messageHandler"  ref="timeSeriesMessageHandler"/>
</bean>

<bean id="timeSeriesMessageHandler" class="com.sungard.energy.aligne.aligneweb.assetManagement.TimeSeriesMessageHandler">
</bean>

"${power.messagebrokerurl}" is tcp://localhost:61616 i.e. JMS activemq running locally on machine.

App Server is listening to this activemq jms, when jms goes down , app server shows following message, which is right since JMS is actually down and it's trying to see if it's up or not at every 5 seconds.

    WARN DefaultMessageListenerContainer:844 - Setup of JMS message listener invoker failed for destination 'queue://PowerEventQueue' - trying to recover. Cause: The *Consumer* is closed
Could not refresh JMS Connection for destination 'queue://PowerEventQueue' - retrying in 5000 ms. Cause: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused: connect

Now when I restart my JMS, app server successfully connects to it and shows following message.

INFO DefaultMessageListenerContainer:893 - Successfully refreshed JMS Connection
WARN CachingConnectionFactory:301 - Encountered a JMSException - resetting the underlying JMS Connection

Now when i take down JMS server again appserver instead of showing connection refused shows following message.

WARN DefaultMessageListenerContainer:844 - Setup of JMS message listener invoker failed for destination 'queue://PowerEventQueue' - trying to recover. Cause: The Session is closed
INFO CachingConnectionFactory:291 - Established shared JMS Connection: ActiveMQConnection {id=ID:ap-pun-ws0430-53381-1437557704588-0:28,clientId=null,started=false}
ERROR DefaultMessageListenerContainer:909 - Could not refresh JMS Connection for destination 'queue://PowerEventQueue' - retrying in 1000 ms. Cause: The JMS connection has failed: java.io.EOFException

and now even if I start JMS server, appserver does not reconnect to it and continuously throws java.io.EOFException

On thing I observed is that at before successful reconnection to JMS, part of log message says , Cause: The Consumer is closed

where-as in other case it says Cause: The Session is closed and also following line

INFO CachingConnectionFactory:291 - Established shared JMS Connection: ActiveMQConnection {id=ID:ap-pun-ws0430-53381-1437557704588-0:28,clientId=null,started=false}
1

1 Answers

1
votes

Value for power.messagebrokerurl was set to

power.messagebrokerurl=tcp://localhost:61616

If I add failover in the beginning of it, I don' see this error.

power.messagebrokerurl=failover:tcp://localhost:61616

Update: With above settings, listener server always expected JMS to be up and running when it starts. So I have to add startupMaxReconnectAttempts attribute with values as 1. By default its value is -1 (I am using ActiveMQ 5.5.0) which signifies that the transport will have no limit to the number of initial connection attempts and that's the reason listener server was not starting.

power.messagebrokerurl=failover:(tcp://localhost:61616)?startupMaxReconnectAttempts=1

You can refer to http://activemq.apache.org/failover-transport-reference.html for all the transport options.