You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by bizcenter <bi...@gmail.com> on 2012/06/28 13:59:32 UTC

master/slave, consumer can not failover

*Deploy the brokers with master/slave, when master stops, consumer can not
reconnect to slave.*

code example:
/String brokerUrl = "failover:(tcp://hostA, tcp://hostB)";
try {
                connection = factory.createConnection();
            // if a durable topic subscription, and client id must be unique
            if (durable && null != clientId && clientId.length() > 0) {
                connection.setClientID(clientId);
            }
            connection.setExceptionListener(this);
            connection.start();

            session = connection.createSession(transacted, ackMode);
            if (isTopic) {
                destination = session.createTopic(subject);
            } else {
                destination = session.createQueue(subject);
            }

            if (isTopic && durable) {
                if (null != this.filter) {
                    consumer = session.createDurableSubscriber((Topic)
destination, consumerName, this.filter, false);
                } else {
                    consumer = session.createDurableSubscriber((Topic)
destination, consumerName);
                }
            } else {
                if (null != this.filter) {
                    consumer = session.createConsumer(destination,
this.filter);
                } else {
                    consumer = session.createConsumer(destination);
                }
            }

            if (this.receiveTimeout == 0) {
                consumer.setMessageListener(this);
            } else {
                consumeMessagesAndClose(connection, session, consumer,
receiveTimeout);
            }
// no execution about closing connection, session, consumer/
------------------------------------------------------------------------------------------

anyone can give me a favor? thanks. (my english is poor...)



--
View this message in context: http://activemq.2283324.n4.nabble.com/master-slave-consumer-can-not-failover-tp4653639.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: master/slave, consumer can not failover

Posted by joesan <co...@gmail.com>.
That seems like a restricted solution that the Consumer should be a servlet.
May I know why?

What I have is a standalone Consumer (for testing purposes). Not sure how
the Production systems are, but the standalone Consumer dies as soon as the
Master is down. I have been looking for a solution to this since yesterday
but without no luck!



--
View this message in context: http://activemq.2283324.n4.nabble.com/master-slave-consumer-can-not-failover-tp4653639p4655344.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: master/slave, consumer can not failover

Posted by bizcenter <bi...@gmail.com>.
Consumer can do failover in web project. Consumer should be a servlet! You
can have a try!

On Tue, Aug 21, 2012 at 2:38 AM, joesan [via ActiveMQ] <
ml-node+s2283324n4655327h55@n4.nabble.com> wrote:

> Did you find a solution to this? I have more or less the same issue. My
> Producer can fail-over but my Consumer dies as soon as the master dies.
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://activemq.2283324.n4.nabble.com/master-slave-consumer-can-not-failover-tp4653639p4655327.html
>  To unsubscribe from master/slave, consumer can not failover, click here<http://activemq.2283324.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4653639&code=Yml6Y2VudGVybmV0QGdtYWlsLmNvbXw0NjUzNjM5fC02NTk4MzI2MTg=>
> .
> NAML<http://activemq.2283324.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://activemq.2283324.n4.nabble.com/master-slave-consumer-can-not-failover-tp4653639p4655343.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: master/slave, consumer can not failover

Posted by joesan <co...@gmail.com>.
Did you find a solution to this? I have more or less the same issue. My
Producer can fail-over but my Consumer dies as soon as the master dies.



--
View this message in context: http://activemq.2283324.n4.nabble.com/master-slave-consumer-can-not-failover-tp4653639p4655327.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: master/slave, consumer can not failover

Posted by bizcenter <bi...@gmail.com>.
broker uri: failover:(tcp://localhost:61616, tcp://localhost:61617)

but the problem still occurs...

my configuration is right, the exception indicates that the client fail from
61616, try to reconnect 61617

--
View this message in context: http://activemq.2283324.n4.nabble.com/master-slave-consumer-can-not-failover-tp4653639p4653664.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: master/slave, consumer can not failover

Posted by Torsten Mielke <to...@fusesource.com>.
Your failover url should read:

String brokerUrl = "failover:(tcp://hostA:61616,tcp://hostB:61617)";


Please try that.


Torsten Mielke
torsten@fusesource.com
tmielke@blogspot.com


On Jun 29, 2012, at 1:24 PM, mickhayes wrote:

> This bit:
> 
> /String brokerUrl = "failover:(tcp://hostA, tcp://hostB)";
> 
> needs to include the port number 61617.
> 
> Does it?
> 
> 
> -----
> Michael Hayes B.Sc. (NUI), M.Sc. (DCU), SCSA SCNA 
> 
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/master-slave-consumer-can-not-failover-tp4653639p4653662.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.





Re: master/slave, consumer can not failover

Posted by mickhayes <mi...@gmail.com>.
This bit:

/String brokerUrl = "failover:(tcp://hostA, tcp://hostB)";

needs to include the port number 61617.

Does it?


-----
Michael Hayes B.Sc. (NUI), M.Sc. (DCU), SCSA SCNA 

--
View this message in context: http://activemq.2283324.n4.nabble.com/master-slave-consumer-can-not-failover-tp4653639p4653662.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: master/slave, consumer can not failover

Posted by bizcenter <bi...@gmail.com>.
Thanks for you answer!

*In my environment, hostA on port 61616, hostB on 61617.*

When master down, slave becomes master. Producer can failover, but consumer
not with the same configuration.

String brokerUrl = "failover:(tcp://localhost:61616,tcp://localhost:61617)";

What troubles me is why the producer works fine, consumer is over.

--
View this message in context: http://activemq.2283324.n4.nabble.com/master-slave-consumer-can-not-failover-tp4653639p4653661.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: master/slave, consumer can not failover

Posted by Torsten Mielke <to...@fusesource.com>.
What's the consumer's logging output? 
When you shut down the master on hostA, the consumer will loose its connection to the broker and should try to reconnect. It will try both of the tcp urls in your list until it reconnects.

Also, can you confirm that your slave broker starts up just fine on the port number that you specified in your failover url of the consumer?


Regards,

Torsten Mielke
torsten@fusesource.com
tmielke@blogspot.com


On Jun 28, 2012, at 1:59 PM, bizcenter wrote:

> *Deploy the brokers with master/slave, when master stops, consumer can not
> reconnect to slave.*
> 
> code example:
> /String brokerUrl = "failover:(tcp://hostA, tcp://hostB)";
> try {
>                connection = factory.createConnection();
>            // if a durable topic subscription, and client id must be unique
>            if (durable && null != clientId && clientId.length() > 0) {
>                connection.setClientID(clientId);
>            }
>            connection.setExceptionListener(this);
>            connection.start();
> 
>            session = connection.createSession(transacted, ackMode);
>            if (isTopic) {
>                destination = session.createTopic(subject);
>            } else {
>                destination = session.createQueue(subject);
>            }
> 
>            if (isTopic && durable) {
>                if (null != this.filter) {
>                    consumer = session.createDurableSubscriber((Topic)
> destination, consumerName, this.filter, false);
>                } else {
>                    consumer = session.createDurableSubscriber((Topic)
> destination, consumerName);
>                }
>            } else {
>                if (null != this.filter) {
>                    consumer = session.createConsumer(destination,
> this.filter);
>                } else {
>                    consumer = session.createConsumer(destination);
>                }
>            }
> 
>            if (this.receiveTimeout == 0) {
>                consumer.setMessageListener(this);
>            } else {
>                consumeMessagesAndClose(connection, session, consumer,
> receiveTimeout);
>            }
> // no execution about closing connection, session, consumer/
> ------------------------------------------------------------------------------------------
> 
> anyone can give me a favor? thanks. (my english is poor...)
> 
> 
> 
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/master-slave-consumer-can-not-failover-tp4653639.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.