简体   繁体   中英

How to organize broker message redelivery in ActiveMQ for PHP Stomp client

I'm trying to implement a broker redelivery with ActiveMQ 5.8.0 and PHP Stomp extension. But this doesn't work as expected.

PHP subscriber that rollbacks messages

define('QUEUE_NAME', '/queue/Task.Test');

$stomp = new Stomp();

$stomp->subscribe(QUEUE_NAME, array(
    'activemq.prefetchSize' => 10,
));

while (true) {

    $tid = uniqid('tid');
    $stomp->begin($tid);

    try {
        $frame = $stomp->readFrame();
        if ($frame) {
            print_r($frame->headers);
            $stomp->ack($frame->headers['message-id'], array('transaction' => $tid));
            echo "Get message {$frame->headers['message-id']}, rollback it", PHP_EOL;
            $stomp->abort($tid);
        } else {
           $stomp->commit($tid);
        }
    } catch (StompException $e) {
        $stomp->abort($tid);
    }
}

ActiveMQ config (scheduler is enabled):

    <plugins>
        <redeliveryPlugin fallbackToDeadLetter="true" sendToDlqIfMaxRetriesExceeded="true">
            <redeliveryPolicyMap>
                <redeliveryPolicyMap>
                    <redeliveryPolicyEntries>
                        <!-- a destination specific policy -->
                        <redeliveryPolicy queue=">" maximumRedeliveries="2" redeliveryDelay="10000" />
                    </redeliveryPolicyEntries>
                    <!-- the fallback policy for all other destinations -->
                    <defaultEntry>
                        <redeliveryPolicy maximumRedeliveries="2" initialRedeliveryDelay="5000" redeliveryDelay="10000" />
                    </defaultEntry>
                </redeliveryPolicyMap>
            </redeliveryPolicyMap>
        </redeliveryPlugin>
    </plugins>

With that config subscriber receives all mesages and rollbacks them, so they returned to the queue, but I want them to be redelivered after some delay. There is special status for ACK: "poison ack" but I don't know how to specify it.

How can I enable redelivery on the broker side?

Actually, redelivery requires NACK command that is defined in STOMP Protocol version >=1.1 . PHP Stomp client supports only version 1.0, so it's impossible to enable redelivery for this extension. However, it's easy to extend Stomp class with nack() method and headers handling. Hope, that this information will be helpful for someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM