Getting Durable Messages After Failover

View: New views
4 Messages — Rating Filter:   Alert me  

Getting Durable Messages After Failover

by DCMH :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This is the first time I'm using ActiveMQ, the version I'm using is 5.2, below is my configuration:

I have 2 ActiveMQ brokers setup in a cluster.

Both brokers have the following conf:
<networkConnectors>
  <networkConnector name="MQ" uri="static://(tcp://{IP of broker 1}:61616,tcp://{IP of broker 2}:61616)"/>
</networkConnectors>
....
<transportConnectors>
  <transportConnector name="openwire" uri="tcp://localhost:61616"/>
  <transportConnector name="ssl" uri="ssl://localhost:61617"/>
  <transportConnector name="stomp" uri="stomp://localhost:61613"/>
  <transportConnector name="xmpp" uri="xmpp://localhost:61222"/>
</transportConnectors>


I have a client use the failover protocol to connect to the broker cluster :
failover://(tcp://{IP of broker 1}:61616,tcp://{IP of broker 2}:61616)

The client intends to consume the durable messages from a topic: DurableTopic.

There is a message producer constantly producing durable messages to a topic: DurableTopic.

When the client starts, it connects to broker 1 and subscribes to the DurableTopic at broker 1 and consumes the messages produced by the message producer. At some time, the client quits abnormally (without unsubscribing to the DurableTopic at broker 1) while the message producer keeps publishing messages.

I suppose that after the client reconnects to the broker cluster (using the same failover protocol) will be able to consume the durable messages generated by the producer since its abnormal exit.

However, I found that there are 2 possible cases:
(i) the client reconnects to broker 1
(ii) the client reconnects to broker 2

In case (i), the outcome is what I expected, the client is able to consume the messages. However, In case (ii), the client is not able to consume those messages after reconnecting to another broker.

It seems to me that when the client connects to another broker, it is not able to resume the previous session even I use the same name to create the durable subscriber.

I have to try to reconnect the client until it reconnects to broker 1 in order to consume the durable messages.


Is there anyway that I can make my client able to consume the durable messages after reconnection (no matter to broker 1 or broker 2)?
Or I have missed anything in the broker configuration?


Much appreciated if anyone can give me some ideas.
Thanks




Re: Getting Durable Messages After Failover

by HarveyCn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I got the same problem. I wonder the answer too.


DCMH wrote:
This is the first time I'm using ActiveMQ, the version I'm using is 5.2, below is my configuration:

I have 2 ActiveMQ brokers setup in a cluster.

Both brokers have the following conf:
<networkConnectors>
  <networkConnector name="MQ" uri="static://(tcp://{IP of broker 1}:61616,tcp://{IP of broker 2}:61616)"/>
</networkConnectors>
....
<transportConnectors>
  <transportConnector name="openwire" uri="tcp://localhost:61616"/>
  <transportConnector name="ssl" uri="ssl://localhost:61617"/>
  <transportConnector name="stomp" uri="stomp://localhost:61613"/>
  <transportConnector name="xmpp" uri="xmpp://localhost:61222"/>
</transportConnectors>


I have a client use the failover protocol to connect to the broker cluster :
failover://(tcp://{IP of broker 1}:61616,tcp://{IP of broker 2}:61616)

The client intends to consume the durable messages from a topic: DurableTopic.

There is a message producer constantly producing durable messages to a topic: DurableTopic.

When the client starts, it connects to broker 1 and subscribes to the DurableTopic at broker 1 and consumes the messages produced by the message producer. At some time, the client quits abnormally (without unsubscribing to the DurableTopic at broker 1) while the message producer keeps publishing messages.

I suppose that after the client reconnects to the broker cluster (using the same failover protocol) will be able to consume the durable messages generated by the producer since its abnormal exit.

However, I found that there are 2 possible cases:
(i) the client reconnects to broker 1
(ii) the client reconnects to broker 2

In case (i), the outcome is what I expected, the client is able to consume the messages. However, In case (ii), the client is not able to consume those messages after reconnecting to another broker.

It seems to me that when the client connects to another broker, it is not able to resume the previous session even I use the same name to create the durable subscriber.

I have to try to reconnect the client until it reconnects to broker 1 in order to consume the durable messages.


Is there anyway that I can make my client able to consume the durable messages after reconnection (no matter to broker 1 or broker 2)?
Or I have missed anything in the broker configuration?


Much appreciated if anyone can give me some ideas.
Thanks



Re: Getting Durable Messages After Failover

by aortiz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You need to replicate the messages between the two brokers.
See http://activemq.apache.org/clustering.html and look for "Master Slave" or "Replicated Message Stores"

--
Open Source Integration
http://fusesource.com

DCMH wrote:
This is the first time I'm using ActiveMQ, the version I'm using is 5.2, below is my configuration:

I have 2 ActiveMQ brokers setup in a cluster.

Both brokers have the following conf:
<networkConnectors>
  <networkConnector name="MQ" uri="static://(tcp://{IP of broker 1}:61616,tcp://{IP of broker 2}:61616)"/>
</networkConnectors>
....
<transportConnectors>
  <transportConnector name="openwire" uri="tcp://localhost:61616"/>
  <transportConnector name="ssl" uri="ssl://localhost:61617"/>
  <transportConnector name="stomp" uri="stomp://localhost:61613"/>
  <transportConnector name="xmpp" uri="xmpp://localhost:61222"/>
</transportConnectors>


I have a client use the failover protocol to connect to the broker cluster :
failover://(tcp://{IP of broker 1}:61616,tcp://{IP of broker 2}:61616)

The client intends to consume the durable messages from a topic: DurableTopic.

There is a message producer constantly producing durable messages to a topic: DurableTopic.

When the client starts, it connects to broker 1 and subscribes to the DurableTopic at broker 1 and consumes the messages produced by the message producer. At some time, the client quits abnormally (without unsubscribing to the DurableTopic at broker 1) while the message producer keeps publishing messages.

I suppose that after the client reconnects to the broker cluster (using the same failover protocol) will be able to consume the durable messages generated by the producer since its abnormal exit.

However, I found that there are 2 possible cases:
(i) the client reconnects to broker 1
(ii) the client reconnects to broker 2

In case (i), the outcome is what I expected, the client is able to consume the messages. However, In case (ii), the client is not able to consume those messages after reconnecting to another broker.

It seems to me that when the client connects to another broker, it is not able to resume the previous session even I use the same name to create the durable subscriber.

I have to try to reconnect the client until it reconnects to broker 1 in order to consume the durable messages.


Is there anyway that I can make my client able to consume the durable messages after reconnection (no matter to broker 1 or broker 2)?
Or I have missed anything in the broker configuration?


Much appreciated if anyone can give me some ideas.
Thanks



Re: Getting Durable Messages After Failover

by DCMH :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for answering.

But my problem is that the 2 brokers are up and running,

scenario as below:


                   A                    B                 C                          
broker 1   ----+--------                                      -------------

broker 2                                           ----+------


Client connects to broker 1 and consume message A and disconnected before unsubscription, message B is published before the client reconnects. Later the client reconnect to broker 2 using the failover protocol. However, it was unable to resume the session established in broker 1 so it cannot consume message B as it was delivered to broker 1. While the client is connecting to broker 2, message C is published and the client is able to consume message C. However, it seems that the session established in broker 1 is still valid and broker 1 still get message C.

Later, the client get disconnected again and reconnects to broker 1 using the failover protocol, it gets message B and C from broker 1.

There are 2 potential problems:
1) the client will not be able to get message B if it keeps connecting to broker 2 after the first reconnection.
2) the client gets a duplication of message C when it connects to broker 1 after the second reconnection.


I have no idea on how to make use of the Replicated Message Stores in this case since both broker 1 and broker 2 are up and running at the same time (working in a cluster, instead of Master-Slave).

Would you mind to explain in more details?

Much appreciated for your help.




You need to replicate the messages between the two brokers.
See http://activemq.apache.org/clustering.html and look for "Master Slave" or "Replicated Message Stores"

--
Open Source Integration
http://fusesource.com