I have a Spring MVC web app running on my server. Recently I wanted to add a functionality to notify any logged in users that their role has changed, so they can logout and in again.
I thought about using JMX, so did a small test and it worked fine, except that its not broadcasting the message. So for example, if i have 2 logged in persons, only 1 is receiving the message.
So my question is, is it possible to broadcast a message with JMX to all instances of a web app (active sessions)?
Edit – using JMS
So I am trying with JMS right now, here is my configuration file:
<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>
This isnt working right now. However it works if I change the ActiveMQTopic to ActiveMQQueue. what am I missing here, and would this work?
I think the short answer is no. JMX is a single connection API which uses RMI over TCP/IP sockets. Best you can do is to serially unicast to all of your instances or use threads and send to all of your web app sessions in parallel over a number of JMX client connections.