1 Reply Latest reply on Jan 14, 2016 10:13 AM by Justin Bertram

    HornetQ pub sub not working on two wildfly 9.0.2 instances

    Massimiliano Masi Newbie

      Hi All,


      I have two wildfly 9.0.2 instances and I want to publish a message from application A, running in instance 1 to application B in instance 1 and application C in instance 2.

      B and C have the same consumer code, just deployed in two different instances.


      The queueing works just fine when producing in the same wildfly instance (A produces, B consumes), but application C never receive the message. C and B start before A.

      I think I am missing some basics here: why instance B is not receiving the message?


      In standalone.xml of instance 1 I created the following connectors (security is disabled):

      <connector name="netty-throughput">
        <param key="port" value="5455"/>
        <param key="batch-delay" value="50"/>
        <connector name="netty">
        <param key="port" value="5445"/>

      and the following acceptor:

      <acceptor name="netty-throughput">
        <param key="port" value="5455"/>
        <param key="batch-delay" value="50"/>
        <param key="direct-deliver" value="false"/>

      I defined a JMS destination as:

                          <jms-queue name="/queue/auditClientConfigurationQueue"> <entry name="/queue/auditClientConfigurationQueue"/> </jms-queue> 

      In instance 2 I have defined the same connector and the same JMS destination.


      The code that I use to produce (from application A instance 1 is:)

      Connection connection = null;
        try {
        // Before starting the connection, we must make sure that
        // there are at least
        // one connector specified, otherwise we need to reverse to
        // the configuration.
        ConnectionFactory cf = HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF);
        connection = cf.createConnection();
        } catch (JMSException e) {
        l.debug("Connection failed, error was: " + e.getMessage());
        l.debug("No default connectors seems to be present, let's fallback with the default (HARDCODED). "
        Map<String, Object> connectionParams = new HashMap<String, Object>();
        connectionParams.put(TransportConstants.PORT_PROP_NAME, "5445");
        connectionParams.put(TransportConstants.HOST_PROP_NAME, "localhost");
        TransportConfiguration transportConfiguration = new TransportConfiguration(
        NettyConnectorFactory.class.getName(), connectionParams);
        try {
        ConnectionFactory cf = HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF,
        connection = cf.createConnection();
        } catch (Throwable exc) {
        l.error("Unable to start the connection on the default ports. Error is: " + exc.getMessage(),
        throw new RuntimeException(exc);
        l.debug("Connection established. Binding to default ports and services");


      then I search the queue:


      l.debug("Loading the JNDI initial context");
        InitialContext jndiContext = null;
        Queue queue = null;
        try {
        jndiContext = new InitialContext();
        queue = (Queue) jndiContext.lookup(QUEUE_NAME);
        } catch (Throwable e) {
        throw new RuntimeException(e);
        l.debug("Loaded the JNDI Initial context. Now looking up to the queue. This is hardcoded to "
        + QUEUE_NAME);


      and I produce:

      l.debug("Starting the session");
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        TextMessage message = session.createTextMessage(myMessage);



      The receiver has the same configuration and connection settings, and it receives as (in a while(true) loop):


      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        L.debug("Starting the consumer");
        MessageConsumer messageConsumer = session.createConsumer(queue);
        while (true) {
        L.debug("Waiting in the queue");
        TextMessage messageReceived = (TextMessage) messageConsumer.receive();
        String received = messageReceived.getText();
        L.debug("Message received: " + received + " delivery time is "
        + messageReceived.getJMSDeliveryTime());
        • 1. Re: HornetQ pub sub not working on two wildfly 9.0.2 instances
          Justin Bertram Master

          Based on the description of your code and configuration it looks to me like the connectors and acceptor you've defined on each instance aren't actually serving any functional purpose so I think you're safe to remove them.  That bit of code you pasted that is supposed to check for a connector won't check anything other than what is passed into the method call.


          Moreover, your application on instance 2 is connecting to the local broker and not to the broker on instance 1 where the messages are actually being sent/hosted.  The only way messages get moved between 2 brokers without user intervention is if the brokers are clustered together.