简体   繁体   English

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

[英]PHP+Stomp+ActiveMq, “AMQ_SCHEDULED_DELAY” not working

I'm using laravel framework based on php.And Stomp+activeMQ. 我正在使用基于php.And Stomp + activeMQ的laravel框架。 Here I need to send something into mq, however the message should be consumed after 180 seconds, not immediately. 在这里我需要发送一些东西到mq,但是消息应该在180秒后消耗,而不是立即消耗。

Option1, I send it with a timestamp, and the consumer will check the timestamp.If interval > 180, then do something and ack(). Option1,我发送时间戳,消费者将检查时间戳。如果间隔> 180,那么做一些事情和ack()。

Option1 is inefficient, for every moment the consumer is checking timestamp but very few messages are acked. Option1是低效的,消费者每时每刻都在检查时间戳,但很少有消息被激活。

Option2, shell_exec("php send.php | at now + 3 minute"), it looks strange. Option2,shell_exec(“php send.php |现在+3分钟”),看起来很奇怪。

Are there any better solutions? 还有更好的解决方案吗?

I have set "AMQ_SCHEDULED_DELAY" according to Lee's advice, however the message will be sent immediately, too.Maybe the delay config can only be used to PUB/SUB but not PTP?Here is my code: 我根据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);

And I remember to set schedulerSupport=true in activemq.xml. 我记得在activemq.xml中设置schedulerSupport = true。

I refer to this: ActiveMq Doc , is this concerned? 我指的是: ActiveMq Doc ,这是关注吗? I don't know.Or is it OK to send 'AMQ_SCHEDULED_DELAY' in header? 我不知道。或者在标题中发送'AMQ_SCHEDULED_DELAY'是否可以? Because ActiveMq Doc: Stomp does not list it as a header. 因为ActiveMq Doc:Stomp不会将其列为标题。

Check your Message Properties The message property scheduledJobId is reserved for use by the Job Scheduler. 检查消息属性消息属性scheduledJobId保留供Job Scheduler使用。 If this property is set before sending, the message will be sent immediately and not scheduled. 如果在发送之前设置了此属性,则将立即发送消息而不安排该消息。 Also, after a scheduled message is received, the property scheduledJobId will be set on the received message so keep this in mind if using something like a Camel Route which might automatically copy properties over when re-sending a message. 此外,在收到预定的消息后,将在收到的消息上设置属性scheduledJobId,因此如果使用类似Camel Route的内容可能会记住这一点,这可能会在重新发送消息时自动复制属性。

edit activemq.xml enable broker schedulerSupport="true" 编辑activemq.xml启用代理schedulerSupport =“true”

eg. 例如。

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

then restart your activemq server 然后重新启动activemq服务器

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

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