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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

ren0909
This post was updated on .
I have this, one producer, two consumers, all same queue. sometimes consumer0 and consumer1 DO able to receive messages consecutively, but most of the time only consumer0 receive half of the message, consumer1 always receive null value. why is this the case, or if there is any setting is wrong. (on one window machine, two brokers runned on two cmd. third cmd is to hit mvn spring-boot:run)

pushed to https://github.com/ren2046/artemis see if anyone could help?

(edit: added to git hub)
Reply | Threaded
Open this post in threaded view
|

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

jbertram
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 <[hidden email]> 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
>