PHP + Stomp + ActiveMq,“AMQ_SCHEDULED_DELAY”不起作用

问题描述 投票:1回答:1

我正在使用基于php.And Stomp + activeMQ的laravel框架。在这里我需要发送一些东西到mq,但是消息应该在180秒后消耗,而不是立即消耗。

Option1,我发送时间戳,消费者将检查时间戳。如果间隔> 180,那么做一些事情和ack()。

Option1是低效的,消费者每时每刻都在检查时间戳,但很少有消息被激活。

Option2,shell_exec(“php send.php |现在+3分钟”),看起来很奇怪。

还有更好的解决方案吗?

我根据Lee的建议设置了“AMQ_SCHEDULED_DELAY”,但是消息也会立即发送。也许延迟配置只能用于PUB / SUB但不能用于PTP?这是我的代码:

        $con = new Stomp(config('app.mq_url'));
        if (!$con->isConnected()) {
            $con->connect();
            $con->setReadTimeout(3);
        }
        $con->begin("Transaction");
        $options =[
            'persistent'=> $persistent,
            'AMQ_SCHEDULED_DELAY' => $delay * 1000
        ];
        $con->send($queue, json_encode($params), $options);
        $con->commit("Transaction");
        $con->disconnect();
        $con->send($queue, json_encode($params), $options);

我记得在activemq.xml中设置schedulerSupport = true。

我指的是:ActiveMq Doc,这是关心的吗?我不知道。或者在标题中发送'AMQ_SCHEDULED_DELAY'是否可以?因为ActiveMq Doc: Stomp没有将其列为标题。

检查消息属性消息属性scheduledJobId保留供Job Scheduler使用。如果在发送之前设置了此属性,则将立即发送消息而不安排该消息。此外,在收到预定的消息后,将在收到的消息上设置属性scheduledJobId,因此如果使用Camel Route等可能在重新发送消息时自动复制属性,请记住这一点。

php delay message-queue stomp
1个回答
0
投票

编辑activemq.xml启用代理schedulerSupport =“true”

例如。

<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}" schedulerSupport="true">

然后重新启动activemq服务器

© www.soinside.com 2019 - 2024. All rights reserved.