You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "Justin Bertram (Jira)" <ji...@apache.org> on 2019/10/03 12:16:00 UTC

[jira] [Resolved] (ARTEMIS-2510) activemq artemis cluster mode can be one consumer ?

     [ https://issues.apache.org/jira/browse/ARTEMIS-2510?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Justin Bertram resolved ARTEMIS-2510.
-------------------------------------
      Assignee:     (was: Clebert Suconic)
    Resolution: Information Provided

Please take this question to the [ActiveMQ User Mailing List|http://activemq.apache.org/contact/#mailing].

> activemq artemis cluster mode can be one consumer ? 
> ----------------------------------------------------
>
>                 Key: ARTEMIS-2510
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-2510
>             Project: ActiveMQ Artemis
>          Issue Type: Wish
>    Affects Versions: 2.10.1
>         Environment: activemq artemis 2.10.1
> the code 
> package org.apache.activemq.artemis.jms.example;
> import javax.jms.Connection;
> /**
>  * A simple example that demonstrates server side load-balancing of messages between the queue instances on different
>  * nodes of the cluster.
>  */
> public class ClusteredQueueExample {
>    public static void main(final String[] args) throws Exception {
>       Connection connection0 = null;
>       Connection connection1 = null;
>       try {
>          // Step 2. Instantiate the Queue
>          Queue queue = ActiveMQJMSClient.createQueue("exampleQueue");
>          // Instantiate connection towards server 0
>          ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616");
>          // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1
>          ConnectionFactory cf1 = new ActiveMQConnectionFactory("tcp://localhost:61617");
>          // Step 6. We create a JMS Connection connection0 which is a connection to server 0
>          connection0 = cf0.createConnection();
>          // Step 7. We create a JMS Connection connection1 which is a connection to server 1
>          connection1 = cf1.createConnection();
>          // Step 8. We create a JMS Session on server 0
>          Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
>          // Step 9. We create a JMS Session on server 1
>          Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
>          // Step 10. We start the connections to ensure delivery occurs on them
>          connection0.start();
>          connection1.start();
>          // Step 11. We create JMS MessageConsumer objects on server 0 and server 1
>          MessageConsumer consumer0 = session0.createConsumer(queue);
>          MessageConsumer consumer1 = session1.createConsumer(queue);
>          Thread.sleep(1000);
>          // Step 12. We create a JMS MessageProducer object on server 0
>          MessageProducer producer = session0.createProducer(queue);
>          // Step 13. We send some messages to server 0
>          final int numMessages = 10;
>          for (int i = 0; i < numMessages; i++) {
>             TextMessage message = session0.createTextMessage("This is text message " + i);
>             producer.send(message);
>             System.out.println("Sent message: " + message.getText());
>          }
>          // Step 14. We now consume those messages on *both* server 0 and server 1.
>          // We note the messages have been distributed between servers in a round robin fashion
>          // JMS Queues implement point-to-point message where each message is only ever consumed by a
>          // maximum of one consumer
>          for (int i = 0; i < numMessages; i += 2) {
>             TextMessage message0 = (TextMessage) consumer0.receive(5000);
>             System.out.println("Got message: " + message0.getText() + " from node 0");
>             TextMessage message1 = (TextMessage) consumer1.receive(5000);
>             System.out.println("Got message: " + message1.getText() + " from node 1");
>          }
>       } finally {
>          // Step 15. Be sure to close our resources!
>          if (connection0 != null) {
>             connection0.close();
>          }
>          if (connection1 != null) {
>             connection1.close();
>          }
>       }
>    }
> }
>            Reporter: jackson.song
>            Priority: Major
>
> Use the clustered-queue demo can be implement one producer send message to artemis queue,but It must be use all (in clusters) consumers to consume?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)