You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by "bob.sandiford@sirsidynix.com" <bo...@sirsidynix.com> on 2019/07/08 17:10:55 UTC

Master / Slave failover - Client connections don't re-connect - using CORE API

I have a (I think) simple master / slave setup of ActiveMQ servers, using
shared file system.  When I shut down the current master, it fails over to
the slave, and when I then restart the original master, it becomes the
standby - which is all just fine.

I'm having problems on the client side, though.  I'm using the Core API, not
JMS.  (Based on the comment in the first bullet point under "Avoiding
Anti-Patterns".  Which I misread to say 'don't use JMS' rather than 'don't
use JMS Template'.  Anyways - at the moment I'm using the Core API).

The client will, on startup, connect just fine to whichever of the two
ActiveMQ servers is the master.

The problem I'm having is on the server failover - my client code isn't
detecting that, and so the existing connections / producers / consumers I
have set up start failing.

The ActiveMQ wiring in Spring Boot looks like this:



I tried refactoring this so that I could directly call
createServerLocatorWithHA, like this:



but that failed on startup with
org.apache.activemq.artemis.api.core.ActiveMQConnectionTimedOutException:
AMQ119013: Timed out waiting to receive cluster topology. Group:null

I create a separate ClientSession for each consumer, and for each producer.

Any ideas?  

Thanks in advance!





--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html

Re: Master / Slave failover - Client connections don't re-connect - using CORE API

Posted by "bob.sandiford@sirsidynix.com" <bo...@sirsidynix.com>.
OK - I have it working.  There was indeed a problem with the ActiveMQ servers
master / slave configs in the broker.xml files for each.  The sections
<ha-policy>, <cluster-connections> were entirely missing, and the
<connectors> only had the local host defined, and not the other one.

Thank you Justin for pointing me in the right direction!



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html

Re: Master / Slave failover - Client connections don't re-connect - using CORE API

Posted by "bob.sandiford@sirsidynix.com" <bo...@sirsidynix.com>.
Thanks.  It's running in a Docker container, so I "docker stop" it.  I can
see the log output as the slave takes over and starts up, and then I can log
into the old slave's ActiveMQ management console.  And, I can see that the
client detects the down master and attempts reconnects.

Having said that - I've tried a number of variations on what you pointed out
- i.e. adding query params to the url.  My url looks like this:

(tcp://activemq-1:61616,tcp://activemq-2:61616)?ha=true&reconnectAttempts=60&retryInterval=1000

and, when I kill the master's Docker container, my client side code goes
into the reconnect logic, and iterates the appropriate number of times to
try to reconnect.  However - it only ever attempts to reconnect to the
original connected server.  So - if when I start up my client code
'activemq-1' is the master and 'activemq-2' is the slave, the client
connects to 'activemq-1'.  When I kill 'activemq-1', the client only
attempts reconnecting to 'activemq-1', and doesn't try 'activemq-2'.

This is logged to the console (yeah - I know the message says 10 times, and
my query reconnectAttempts is set to 60 - I still have a hard override in my
code.  I'll clean that up before I'm all done...):

WARN  o.a.activemq.artemis.core.client - AMQ212005: Tried 10 times to
connect. Now giving up on reconnecting it.

I can see both servers listed in the '

I've tried it with 'activemq-1' being the master and 'activemq-2' being the
slave, I've tried it the other way around, and I've tried it with only one
server running, and starting up the other once the client has initialized. 
Same basic problem with each attempt.

During the reconnect attempts, I can see (in the debugger) that
ClientSessionFactyoryImpl's serverLocator has both 'activemq-1' and
'activemq-2' in the 'initialConnectors' array.

This might be a clue.  I don't know what the Topology object should look
like, but the 'topology' hash map is empty.  And, this output when I turned
on 'debug' logging for activemq classes:

2019-07-08 21:18:31,883 UTC [main] DEBUG
o.a.a.a.c.c.i.ClientSessionFactoryImpl - ClientSessionFactoryImpl received
backup update for live/backup pair =
TransportConfiguration(name=null:tcp://activemq-2:61616,
factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory)
?port=61616&host=activemq-2&reconnectAttempts=60&ha=true&retryInterval=1000
/ null but it didn't belong to
TransportConfiguration(name=null:tcp://activemq-2:61616,
factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory)
?port=61616&host=activemq-2&reconnectAttempts=60&ha=true&retryInterval=1000


Further - here's the console log debug output for one iteration of
attempting to reconnect on the client:

2019-07-08 21:31:48,619 UTC [Thread-2 (ActiveMQ-client-global-threads)]
DEBUG o.a.a.a.c.r.i.netty.NettyConnector - Connector NettyConnector
[host=activemq-2, port=61616, httpEnabled=false, httpUpgradeEnabled=false,
useServlet=false, servletPath=/messaging/ActiveMQServlet, sslEnabled=false,
useNio=true] using native epoll
2019-07-08 21:31:48,620 UTC [Thread-2 (ActiveMQ-client-global-threads)]
DEBUG o.a.activemq.artemis.core.client - AMQ211002: Started EPOLL Netty
Connector version 4.1.31.Final to activemq-2:61616
2019-07-08 21:31:48,625 UTC [Thread-2 (ActiveMQ-client-global-threads)]
DEBUG o.a.a.a.c.r.i.netty.NettyConnector - Remote destination:
activemq-2/10.5.85.142:61616
2019-07-08 21:31:49,896 UTC [Thread-2 (ActiveMQ-client-global-threads)]
DEBUG o.a.a.a.c.c.i.ClientSessionFactoryImpl - Connector towards
NettyConnector [host=activemq-2, port=61616, httpEnabled=false,
httpUpgradeEnabled=false, useServlet=false,
servletPath=/messaging/ActiveMQServlet, sslEnabled=false, useNio=true]
failed
2019-07-08 21:31:49,899 UTC [Thread-2 (ActiveMQ-client-global-threads)]
DEBUG o.a.a.a.c.c.i.ClientSessionFactoryImpl - Backup is not active, trying
original connection configuration now.
2019-07-08 21:31:50,901 UTC [Thread-2 (ActiveMQ-client-global-threads)]
DEBUG o.a.a.a.c.c.i.ClientSessionFactoryImpl - Trying reconnection attempt
1/10
2019-07-08 21:31:50,902 UTC [Thread-2 (ActiveMQ-client-global-threads)]
DEBUG o.a.a.a.c.c.i.ClientSessionFactoryImpl - Trying to connect with
connectorFactory =
org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory@31973858,
connectorConfig=TransportConfiguration(name=null:tcp://activemq-2:61616,
factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory)
?port=61616&host=activemq-2&reconnectAttempts=60&ha=true&retryInterval=1000

where I see "Backup is not active, trying original connection configuration
now."

(Sorry - I inherited the ActiveMQ master / backup setup from another
engineer who isn't with the company any more - and I suspect from the above
that it might not be set up correctly?)

Thanks!

Any thoughts?

Thanks!



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html

Re: Master / Slave failover - Client connections don't re-connect - using CORE API

Posted by Justin Bertram <jb...@apache.org>.
One more thing...

Since you're using share-store then you either need to really kill the
broker (e.g. kill -9 <pid>) to trigger failover or set
<failover-on-shutdown>true</failover-on-shutdown> if you're stopping the
broker gracefully, e.g.:

  <ha-policy>
     <shared-store>
        <master>
           <failover-on-shutdown>true</failover-on-shutdown>
       </master>
      </shared-store>
  </ha-policy>


Justin



On Mon, Jul 8, 2019 at 3:03 PM bob.sandiford@sirsidynix.com <
bob.sandiford@sirsidynix.com> wrote:

> Sorry about the code not showing up.  I edited the post to put it in.
>
> Thanks for the reply - a simple usage of your suggestion didn't work - but
> it did change the behaviour, so I'll pursue the possible values for the
> query params on the url specification.
>
> Bob.
>
>
>
> --
> Sent from:
> http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
>

Re: Master / Slave failover - Client connections don't re-connect - using CORE API

Posted by "bob.sandiford@sirsidynix.com" <bo...@sirsidynix.com>.
Sorry about the code not showing up.  I edited the post to put it in.

Thanks for the reply - a simple usage of your suggestion didn't work - but
it did change the behaviour, so I'll pursue the possible values for the
query params on the url specification.

Bob.



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html

Re: Master / Slave failover - Client connections don't re-connect - using CORE API

Posted by Justin Bertram <jb...@apache.org>.
None of the code or configuration came through on your first email. In the
second email it didn't come through either, but some of it is visible on
the Nabble web page.

That said, I think the problem is the URL you're using (i.e.
"(tcp://activemq-1:61616,tcp://activemq-2:61616)"). You aren't specifying
the proper parameters to enable fail-over & reconnection. You should use
something like this:


(tcp://activemq-1:61616,tcp://activemq-2:61616)?ha=true&reconnectAttempts=-1

I recommend you take a look at the "multiple-failover-failback" example
shipped with the broker in
<ARTEMIS_HOME>/examples/features/ha/multiple-failover-failback. It
demonstrates how to do what your attempting.

To be clear, the Artemis client doesn't support the "failover://" schema.
That's used by the OpenWire client (i.e. the client shipped with ActiveMQ
5.x).


Justin

On Mon, Jul 8, 2019 at 12:27 PM bob.sandiford@sirsidynix.com <
bob.sandiford@sirsidynix.com> wrote:

> Sorry - a couple of other things.
>
> The exception I get on the client (when I shut down the master ActiveMQ)
> and
> try to send a message to ActiveMQ is:
>
>
>
> I'm using a URL like this:
>
>
> I tried:
>
> but got an exception like this:
>
>
>
>
>
> --
> Sent from:
> http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
>

Re: Master / Slave failover - Client connections don't re-connect - using CORE API

Posted by "bob.sandiford@sirsidynix.com" <bo...@sirsidynix.com>.
Sorry - a couple of other things.

The exception I get on the client (when I shut down the master ActiveMQ) and
try to send a message to ActiveMQ is:



I'm using a URL like this:


I tried:

but got an exception like this:





--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html