2013-07-30 9 views
0

的JBoss AS7 JMS集羣我有在JBoss 7 JMS集羣中運行的Spring web的問題。與Spring應用

我建立JMS集羣由該article - 羣集是使用共享日記。我使用example的live1和backup1配置。例如,在包含Message Driven Bean的應用程序正在運行的實時和備份服務器之間切換。

我創建簡單的Spring Web應用程序,其註冊JMS偵聽器。

我的JMS-config.xml文件是在這裏:

<?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看起來是這樣的:

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); 
     } 
    } 

} 

當我開始直播服務器,消息由ExampleListener處理 - 這是確定。當我啓動備份服務器時,出現錯誤javax.naming.NameNotFoundException由於ConnectionFactory在JNDI下沒有公開給備份服務器 - 那麼只有主服務器在工作,它不是一個羣集。當現場服務器失敗時,現在沒有備份在這裏。

當我嘗試爲ConnectionFactory設置lazy-init="true"loadOnStartup="false"(+代理接口)並且testQueue沒有任何變化,因爲listenerContainer將在備份服務器啓動時創建它。我需要listenerContainer將等到備份服務器成爲活動狀態,然後再連接到隊列。

我也試過jms/RemoteConnectionFactory,但結果相同 - JNDI名下的資源在備份服務器上不可用。

這是一個使用maven mvn package(Eclipse項目)構建它的webapp source code。 這是一個簡單的JMS client source code(Eclipse項目)。

回答