Send message to all nodes in JBoss cluster domain
Asked Answered
W

1

7

I'm running a JBoss Wildfly 8.1.0.Final in domain mode with two nodes ("host-1" and "host-2") and need to send a message from one node to all nodes in the cluster in order to execute a certain action on all of them. The client that sends the message and the message receiver should be in the same EAR.

Since the question has been unanswered and uncommented on so far, I'll break the question down into simpler parts. Please feel free to answer or comment on only a subset so I can investigate further.

  1. Am I correct in assuming that this is a valid use case for a message driven bean? If not, why? In that case, the remainder of the question is probably pointless.

  2. I created a javax.jms.Topic in the domain.xml of the JBoss cluster's domain-controller, "host-1". Correct in principle?

  3. The client that intends to send the message, looks up the Topic and ConnectionFactory via JNDI (as opposed to, e.g., having it injected). Is that the right approach?

  4. The MDB which is to receive the message is configured to listen to that Topic via an @ActivationConfigProperty. Correct?

The above setup works locally, i.e. the message is received only by the node that sends it. It is not received by other nodes. The client code that sends the message is triggered from a WAR, and the message is received by a MDB in an EJB module in the same EAR.

I am unsure whether we need a RemoteConnectionFactory or whether we need to use a different way to look up the topic (currently injected into MDB and looked up by the client as java:/jms/rmcTopic), since it is actually defined on a remote host.

This is my topic in domain.xml. I know the <clustered> tag is deprecated, but I could not find recent documentation for how this is done with Wildfly 8.1.

<subsystem xmlns="urn:jboss:domain:messaging:2.0">
    <hornetq-server>
        <clustered>true</clustered>
        <cluster-user>hornetqcluster</cluster-user>
        <cluster-password>hornetqcluster</cluster-password>
        <!-- ... -->
        <jms-connection-factories>
             <!-- ... -->
             <connection-factory name="RemoteConnectionFactory">
                  <connectors>
                        <connector-ref connector-name="http-connector"/>
                  </connectors>
                  <entries>
                      <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
                  </entries>
             </connection-factory>
        </jms-connection-factories>
        <!-- ... -->
        <jms-destinations>
           <!-- ... -->
           <jms-topic name="rmcTopic">
                 <entry name="java:/jms/rmcTopic"/>
           </jms-topic>
        </jms-destinations>
    </hornetq-server>
 </subsystem>

The MDB is packaged as an EJB module in an EAR, and the MDB annotations are:

@MessageDriven(name = "ConfigurationMDB", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/rmcTopic"),
@ActivationConfigProperty(propertyName = "connectionFactoryJndiName", propertyValue = "RemoteConnectionFactory"),
@ActivationConfigProperty(propertyName = "addressList", propertyValue = "host-1"),
@ActivationConfigProperty(propertyName = "useSharedSubscriptionInClusteredContainer", propertyValue = "false") })
public class ConfigurationMDB implements MessageListener

Log output indicates that useSharedSubscriptionInClusteredContainer and connectionFactoryJndiName are not supported, but again I'm keeping them as a reference to failed attempts of mine :-)

The code that sends the message is inside a WAR in the same EAR:

Context ic = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) ic.lookup("java:jboss/exported/jms/RemoteConnectionFactory");
Topic topic = (Topic) ic.lookup("java:/jms/rmcTopic");
Connection connection = cf.createConnection("hornetqcluster", "hornetqcluster");
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer publisher = session.createProducer(topic);
connection.start();
TextMessage message = session.createTextMessage("Test");
publisher.send(message);

Any help is greatly appreciated.

Wheresoever answered 25/9, 2014 at 10:11 Comment(1)
I'd be also interested in any way to make this question more clear or easier to answer since it has not received any attention yet.Wheresoever
B
0

1st there is no master or slave in jboss you should define everything at profile level and associate a server group to that profile and finally deploy the application inside the cluster 2nd which profile are you using ? is it full-ha ? otherwise queue will not be clustered

Breastfeed answered 15/6, 2015 at 23:59 Comment(3)
"master" and "slave" are just names that someone else assigned - sorry, they were meaningless for the question, will remove. Can you elaborate on what exactly in the full-ha profile makes the queue clustered? Probably that's the reason.Wheresoever
<hornetq-server> section you should see <cluster-password>${jboss.messaging.cluster.password:CHANGE ME!!}</cluster-password> You should change the passwordBreastfeed
Other pieces of the hornetq section is needed to obtain JMS in Cluster But generally is better to use the full-ha profile to have itBreastfeed

© 2022 - 2024 — McMap. All rights reserved.