osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Two-node cluster, one producer, different consumer, wont work most of the time


Can you work up a reproducible test-case (e.g. based on one of the
clustered examples shipped with Apache ActiveMQ Artemis) and push it to
GitHub? That would be much simpler to investigate than a bunch of cut and
pasted code and xml.


Justin

On Sat, Dec 30, 2017 at 4:02 AM, ren0909 <timothyrafyung@xxxxxxxxx> wrote:

> I tried:
> 1) 1 connection factories HA, one producer, two consumer.receive, all the
> same queue.
> 2) 2 connection factories HA, one producer, two consumer.receive, all the
> same queue.
> 3) 2 connection factories with direct tcp connection, one producer, two
> consumer.receive, all the same queue.
>
> i produce message with text 0 to 10
> and then consumer0.receive, consumer1.receive consecutively,
> but most of the time only consumer0 received result 0 2 4 6 8 10, or 1 3 5
> 7
> 9
> and consumer1.receive are all null
>
> why sometimes it works (two consumers receive successfully with different
> messages)
> but most of the time only one consumer can receive its message, the other
> shown as null?
>
> an example of code i have:
> initialContext = new InitialContext();
>
>                         Queue queue = (Queue) initialContext.lookup("queue/
> exampleQueue");
>
>                  // Step 3. Look-up a JMS Connection Factory object from
> JNDI on
> server 0
>                 ConnectionFactory connectionFactory = (ConnectionFactory)
> initialContext.lookup("ConnectionFactory");
>
>                         Connection conn = connectionFactory.createConnection("tim",
> "yung");
>
>                         Thread.sleep(5000);
>
>                         connection0 = connectionFactory.createConnection("tim",
> "yung");
>
>                         connection1 = connectionFactory.createConnection("tim",
> "yung");
>
>                         connection0.start();
>
>                         connection1.start();
>
>                         Session session0 = connection0.createSession(
> false,
> Session.AUTO_ACKNOWLEDGE);
>
>                         Session session1 = connection1.createSession(
> false,
> Session.AUTO_ACKNOWLEDGE);
>
>                         MessageConsumer consumer0 =
> session0.createConsumer(queue);
>
>                         MessageConsumer consumer1 =
> session1.createConsumer(queue);
>
>                         MessageProducer producer0 =
> session0.createProducer(queue);
>
>                         final int numMessages = 18;
>
>                         for (int i = 0; i < numMessages; i++) {
>
>                                 TextMessage message0 =
> session0.createTextMessage("Queue message: " +
> i);
>
>                                 producer0.send(message0);
>                                 System.out.println(message0.getText());
>
>                         }
>
>                         for (int i = 0; i < 9; i++) {
>
>                                 TextMessage received0 = (TextMessage)
> consumer0.receive(5000);
>
>                                 if (received0 == null) {
>                                         System.out.println("consumer0:
> null");
>                                         //throw new
> IllegalStateException("Message is null!");
>                                 }else {
>                                         System.out.println("consumer0:" +
> received0.getText());
>
>                                 }
>
>                                 TextMessage received1 = (TextMessage)
> consumer1.receive(5000);
>
>                                 if (received1 == null) {
>                                         System.out.println("consumer1:
> null");
>                                         //throw new
> IllegalStateException("Message is null!");
>                                 }else {
>                                         System.out.println("consumer1:
> "+received1.getText());
>                                 }
>
>                         }
>
> <connectors>
>          <connector name="netty-connector">tcp://0.0.0.0:61616</connector>
>
>
>       </connectors>
>
>
>       <acceptors>
>          <acceptor name="netty-acceptor">tcp://0.0.0.0:61616</acceptor>
>
>       </acceptors>
>
>
>       <broadcast-groups>
>          <broadcast-group name="my-broadcast-group">
>             <group-address>231.7.7.7</group-address>
>             <group-port>9876</group-port>
>             <broadcast-period>100</broadcast-period>
>             <connector-ref>netty-connector</connector-ref>
>          </broadcast-group>
>       </broadcast-groups>
>
>       <discovery-groups>
>          <discovery-group name="my-discovery-group">
>             <group-address>231.7.7.7</group-address>
>             <group-port>9876</group-port>
>             <refresh-timeout>1000</refresh-timeout>
>          </discovery-group>
>       </discovery-groups>
>
>       <cluster-connections>
>          <cluster-connection name="my-cluster">
>             <connector-ref>netty-connector</connector-ref>
>             <retry-interval>500</retry-interval>
>             <use-duplicate-detection>true</use-duplicate-detection>
>             <message-load-balancing>ON_DEMAND</message-load-balancing>
>             <max-hops>1</max-hops>
>             <discovery-group-ref discovery-group-name="my-
> discovery-group"/>
>          </cluster-connection>
>       </cluster-connections>
>
>       <address-settings>
>          <address-setting match="#">
>             <redistribution-delay>0</redistribution-delay>
>          </address-setting>
>       </address-settings>
>
>
>
> --
> Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-
> f2341805.html
>