简体   繁体   English

如何在ActiveMQ for PHP Stomp客户端中组织代理消息重新交付

[英]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. 我正在尝试使用ActiveMQ 5.8.0和PHP Stomp扩展实现代理重新交付。 But this doesn't work as expected. 但这不能按预期工作。

PHP subscriber that rollbacks messages 回滚消息的PHP订阅者

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): ActiveMQ配置(已启用调度程序):

    <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. ACK具有特殊状态:“毒气ack”,但我不知道如何指定它。

How can I enable redelivery on the broker side? 如何在经纪人方面启用重新交付?

Actually, redelivery requires NACK command that is defined in STOMP Protocol version >=1.1 . 实际上,重新交付需要在STOMP协议版本> = 1.1中定义的NACK命令。 PHP Stomp client supports only version 1.0, so it's impossible to enable redelivery for this extension. PHP Stomp客户端仅支持1.0版,因此无法为该扩展启用重新交付。 However, it's easy to extend Stomp class with nack() method and headers handling. 但是,使用nack()方法和标头处理扩展Stomp类很容易。 Hope, that this information will be helpful for someone. 希望这些信息对某人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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