ActiveMQ Artemis broadcast sending messages to only one server in the group

試著忘記壹切 提交于 2020-06-29 03:57:26

问题


I am new to Artemis. I have two artemis server up and running but when I send broadcast messages then the messages are sent to only one server.

Following is the snippet of broker.xml of brokerOne

<!-- Acceptor for every supported protocol -->
         <acceptor name="artemis">tcp://0.0.0.0:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;amqpMinLargeMessageSize=102400;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true</acceptor>

         <!-- AMQP Acceptor.  Listens on default AMQP port for AMQP traffic.-->
         <acceptor name="amqp">tcp://0.0.0.0:5672?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=AMQP;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpMinLargeMessageSize=102400;amqpDuplicateDetection=true</acceptor>

         <!-- STOMP Acceptor. -->
         <acceptor name="stomp">tcp://0.0.0.0:61613?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=STOMP;useEpoll=true</acceptor>

         <!-- HornetQ Compatibility Acceptor.  Enables HornetQ Core and STOMP for legacy HornetQ clients. -->
         <acceptor name="hornetq">tcp://0.0.0.0:5445?anycastPrefix=jms.queue.;multicastPrefix=jms.topic.;protocols=HORNETQ,STOMP;useEpoll=true</acceptor>

         <!-- MQTT Acceptor -->
         <acceptor name="mqtt">tcp://0.0.0.0:1883?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=MQTT;useEpoll=true</acceptor>

      </acceptors>

      <connectors>
   <connector name="nettyartemis">tcp://10.5.100.1:61616</connector>
</connectors>

<discovery-groups>
   <discovery-group name="my-discovery-group">
      <local-bind-address>10.5.100.1</local-bind-address>
      <group-address>231.7.7.7</group-address>
      <group-port>9876</group-port>
      <refresh-timeout>10000</refresh-timeout>
   </discovery-group>
</discovery-groups>

<broadcast-groups>
   <broadcast-group name="my-broadcast-group">
      <local-bind-address>10.5.100.1</local-bind-address>
      <local-bind-port>5432</local-bind-port>
      <group-address>231.7.7.7</group-address>
      <group-port>9876</group-port>
      <broadcast-period>2000</broadcast-period>
      <connector-ref>nettyartemis</connector-ref>
   </broadcast-group>
</broadcast-groups>

<cluster-connections>
         <cluster-connection name="my-cluster">
            <connector-ref>nettyartemis</connector-ref>
            <retry-interval>500</retry-interval>
            <use-duplicate-detection>true</use-duplicate-detection>
            <message-load-balancing>STRICT</message-load-balancing>
            <max-hops>1</max-hops>
            <discovery-group-ref discovery-group-name="my-discovery-group"/>
         </cluster-connection>
      </cluster-connections>

and the snippet of broker.xml of brokerTwo

 <!-- Acceptor for every supported protocol -->
         <acceptor name="artemis">tcp://0.0.0.0:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;amqpMinLargeMessageSize=102400;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true</acceptor>

         <!-- AMQP Acceptor.  Listens on default AMQP port for AMQP traffic.-->
         <acceptor name="amqp">tcp://0.0.0.0:5672?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=AMQP;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpMinLargeMessageSize=102400;amqpDuplicateDetection=true</acceptor>

         <!-- STOMP Acceptor. -->
         <acceptor name="stomp">tcp://0.0.0.0:61613?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=STOMP;useEpoll=true</acceptor>

         <!-- HornetQ Compatibility Acceptor.  Enables HornetQ Core and STOMP for legacy HornetQ clients. -->
         <acceptor name="hornetq">tcp://0.0.0.0:5445?anycastPrefix=jms.queue.;multicastPrefix=jms.topic.;protocols=HORNETQ,STOMP;useEpoll=true</acceptor>

         <!-- MQTT Acceptor -->
         <acceptor name="mqtt">tcp://0.0.0.0:1883?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=MQTT;useEpoll=true</acceptor>

      </acceptors>


      <connectors>
   <connector name="nettyartemistwo">tcp://10.5.100.2:61616</connector>
</connectors>

<discovery-groups>
   <discovery-group name="my-discovery-group">
      <local-bind-address>10.5.100.2</local-bind-address>
      <group-address>231.7.7.7</group-address>
      <group-port>9876</group-port>
      <refresh-timeout>10000</refresh-timeout>
   </discovery-group>
</discovery-groups>

<broadcast-groups>
   <broadcast-group name="my-broadcast-group">
      <local-bind-address>10.5.100.2</local-bind-address>
      <local-bind-port>5432</local-bind-port>
      <group-address>231.7.7.7</group-address>
      <group-port>9876</group-port>
      <broadcast-period>2000</broadcast-period>
      <connector-ref>nettyartemistwo</connector-ref>
   </broadcast-group>
</broadcast-groups>

<cluster-connections>
         <cluster-connection name="my-cluster">
            <connector-ref>nettyartemistwo</connector-ref>
            <retry-interval>500</retry-interval>
            <use-duplicate-detection>true</use-duplicate-detection>
            <message-load-balancing>STRICT</message-load-balancing>
            <max-hops>1</max-hops>
            <discovery-group-ref discovery-group-name="my-discovery-group"/>
         </cluster-connection>
      </cluster-connections>

And here is how I am creating producer/consumer and sending messages. I took this example from artemis documentation and modified it to fit my case.

public class Main {

    public static void main(String[] args) {
        try {
            new Main().runExample();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void runExample() throws Exception {
        InitialContext initialContext = null;

        Connection connectionA = null;
        Connection connectionB = null;

        try {
            Properties properties = new Properties();

            properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
            properties.put("connectionFactory.ConnectionFactory", "udp://231.7.7.7:9876");
            properties.put("queue.queue/ExpiryQueue", "ExpiryQueue");

            initialContext = new InitialContext(properties);

            Queue queue = (Queue) initialContext.lookup("queue/ExpiryQueue");

            ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("ConnectionFactory");

            Thread.sleep(5000);
            //brokers of both servers has same username and password
            connectionA = connectionFactory.createConnection("admin", "admin");
            connectionB = connectionFactory.createConnection("admin", "admin");

            Session sessionA = connectionA.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Session sessionB = connectionB.createSession(false, Session.AUTO_ACKNOWLEDGE);

             System.out.println("Session A - " + ((ClientSessionInternal)
              ((org.apache.activemq.artemis.jms.client.ActiveMQSession) sessionA)
              .getCoreSession()).getConnection().getRemoteAddress());
              System.out.println("Session B - " + ((ClientSessionInternal)
              ((org.apache.activemq.artemis.jms.client.ActiveMQSession) sessionB)
              .getCoreSession()).getConnection().getRemoteAddress());

            MessageProducer producerA = sessionA.createProducer(queue);
            MessageProducer producerB = sessionB.createProducer(queue);

            final int numMessages = 10;

            for (int i = 0; i < numMessages; i++) {
                TextMessage messageA = sessionA.createTextMessage("A:This is text message " + i);
                producerA.send(messageA);
                System.out.println("Sent message: " + messageA.getText());

                TextMessage messageB = sessionB.createTextMessage("B:This is text message " + i);
                producerB.send(messageB);
                System.out.println("Sent message: " + messageB.getText());
            }

            connectionA.start();
            connectionB.start();

            consume(sessionA, queue, numMessages, "A");
            consume(sessionB, queue, numMessages, "B");

        } finally {
            // Step 10. Be sure to close our resources!

            if (connectionA != null) {
                connectionA.close();
            }
            if (connectionB != null) {
                connectionB.close();
            }

            if (initialContext != null) {
                initialContext.close();
            }
        }
    }

    private static void consume(Session session, Queue queue, int numMessages, String node) throws JMSException {
        MessageConsumer consumer = session.createConsumer(queue);

        for (int i = 0; i < numMessages; i++) {
            TextMessage message = (TextMessage) consumer.receive(2000);
            System.out.println("Got message: " + message.getText() + " from node " + node);
        }

        System.out.println("receive other message from node " + node + ": " + consumer.receive(2000));
    }
}

I am executing the main class on the system with IP (10.5.100.1) and it is sending messages to only the IP (10.5.100.2). Why my program is behaving this way?

Log Entry (IP address are changed)

2020-06-12 10:59:22,295 INFO  [org.apache.activemq.artemis.core.server] AMQ221027: Bridge ClusterConnectionBridge@325b0cb0 [name=$.artemis.internal.sf.my-cluster.f07b3018-ac69-11ea-a5d3-005056ad8516, queue=QueueImpl[name=$.artemis.internal.sf.my-cluster.f07b3018-ac69-11ea-a5d3-005056ad8516, postOffice=PostOfficeImpl [server=ActiveMQServerImpl::serverUUID=03451127-a9c9-11ea-992a-005056ad92be], temp=false]@5b037424 targetConnector=ServerLocatorImpl (identity=(Cluster-connection-bridge::ClusterConnectionBridge@325b0cb0 [name=$.artemis.internal.sf.my-cluster.f07b3018-ac69-11ea-a5d3-005056ad8516, queue=QueueImpl[name=$.artemis.internal.sf.my-cluster.f07b3018-ac69-11ea-a5d3-005056ad8516, postOffice=PostOfficeImpl [server=ActiveMQServerImpl::serverUUID=03451127-a9c9-11ea-992a-005056ad92be], temp=false]@5b037424 targetConnector=ServerLocatorImpl [initialConnectors=[TransportConfiguration(name=nettyartemistwo, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61616&host=10-5-100-2], discoveryGroupConfiguration=null]]::ClusterConnectionImpl@2090289474[nodeUUID=03451127-a9c9-11ea-992a-005056ad92be, connector=TransportConfiguration(name=nettyartemis, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61616&host=10-5-100-1, address=, server=ActiveMQServerImpl::serverUUID=03451127-a9c9-11ea-992a-005056ad92be])) [initialConnectors=[TransportConfiguration(name=nettyartemistwo, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61616&host=10-5-100-2], discoveryGroupConfiguration=null]] is connected

来源:https://stackoverflow.com/questions/62345964/activemq-artemis-broadcast-sending-messages-to-only-one-server-in-the-group

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!