Search code examples
phpactivemq-classicfailoverstomp

PHP stomp client doesn't failover to secondary MQ


I'm trying implement a fail-over function for my consumer, written in PHP. Below are the structure:

<?php
require_once $root.'lib/stomp.php';

$con = new Stomp('failover://(tcp://MQ1:61612,tcp://MQ2:61612)?randomize=false');
$con->connect(username,password);
$con->subscribe($receiveQueue, array('ack' => 'client','activemq.prefetchSize' => 1));

while ($con->hasFrameToRead() == true) {
    $con->begin("tx1");

    if($con->isConnected() == false) {
        $con->_reconnect();
    }

    // bla bla bla...
}

$con->disconnect();
?>

When I start the PHP client, it is able to connect MQ1, but after I kill the MQ service in MQ1 server, it doesn't fail-over to MQ2.

May I know is there any part that I have missed out? Or is there any necessary configuration required on the MQ server side?

Thank you in advance :)


Solution

  • From the PHP client's I've seen so far the failover only works for connect, and doesn't reconnect afterwards. I'm not sure of the state of the particular client you are using but it would be worth it for you to check with its developers to see if that's really supported.

    It should also be noted that in order to properly detect a connection loss the client would either need to be using the socket actively, or be doing some sort of keep alive checking in the background using STOMP v1.1 or later heart beats, otherwise a connection loss could go unnoticed.

    You best bet is to work with the developers of the PHP Stomp client you are using to find some resolution.