我有一臺運行在我的服務器上的Spring MVC web應用程序。最近我想增加一項功能來通知任何登錄用戶他們的角色已經改變,所以他們可以註銷並重新登錄。使用JMX/JMS將消息廣播到Web應用程序的所有會話?
我想過使用JMX,所以做了一個小測試,它工作正常,除了它沒有廣播消息。例如,如果我有2個登錄人員,則只有1個人正在接收該消息。
所以我的問題是,是否有可能使用JMX向Web應用程序的所有實例(活動會話)廣播消息?
編輯 - 使用JMS
所以我跟JMS努力,現在,這裏是我的配置文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="connectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
<bean id="msgDestination"
class="org.apache.activemq.command.ActiveMQTopic">
<constructor-arg value="userToLogout.topic"/>
</bean>
<bean id="jmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="pubSubDomain" value="true"/>
<property name="receiveTimeout" value="10000"/>
</bean>
<bean id="userNotifier"
class="com.cap.messaging.UserNotifier">
<property name="destination" ref="msgDestination"/>
<property name="jmsTemplate" ref="jmsTemplate"/>
</bean>
<bean id="userNotificationListener"
class="com.cap.messaging.UserNotificationListener">
</bean>
<bean
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destinationName" value="userToLogout.topic" />
<property name="messageListener" ref="userNotificationListener" />
</bean>
這個心不是現在的工作。但是,如果我將ActiveMQTopic更改爲ActiveMQQueue,它就可以工作。我在這裏錯過了什麼,並會這樣工作?
如果有人對解決方案感興趣,我只是添加了一個Application範圍bean,並且模擬了發佈 - 訂閱通信。有點伎倆。 – Elio 2012-02-20 12:47:20