1
votes

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?

1
you have already got a redeliveryDelay on your redeliveryPolicy. What do you want more ?willome

1 Answers

2
votes

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.