I have a problem with Spring webapp running on JBoss 7 JMS Cluster.
I set up JMS cluster by this article - cluster is using shared journal. I'm using live1 and backup1 configuration from the example. For the example switching between live and backup server with app which contains Message Driven Bean is working.
I created simple Spring web app which register JMS listener.
My jms-config.xml is here:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="ConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="ConnectionFactory" />
</bean>
<bean id="testQueue" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jms/queue/test" />
</bean>
<bean id="listener" class="eu.cuptech.jms.ExampleListener" />
<bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="ConnectionFactory" />
<property name="destination" ref="testQueue" />
<property name="messageListener" ref="listener" />
</bean>
</beans>
ExampleListener.java looks like this:
package eu.cuptech.jms;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
public class ExampleListener implements MessageListener {
public void onMessage(Message message) {
try {
String msg = ((TextMessage) message).getText();
System.out.println("MESSAGE TEXT: " + msg);
} catch (JMSException e) {
throw new RuntimeException(e);
}
}
}
When I start the live server, messages are handled by ExampleListener - it is OK. When I start backup server I got error javax.naming.NameNotFoundException beacause of ConnectionFactory
is not exposed under JNDI for backup server - then only main server is working it is not a cluster. When live server fails now no backup is here.
When I try set lazy-init="true"
and loadOnStartup="false"
(+ proxy interface) for ConnectionFactory and testQueue nothing change because listenerContainer will create it when backup server is started. I need listenerContainer will wait until backup server become live and then will connect to the Queue.
I tried jms/RemoteConnectionFactory
also, but with the same result - resource under JNDI name is not available on backup server.
Here is a webapp source code build it using maven mvn package
(Eclipse project).
Here is a simple JMS client source code (Eclipse project).