doufeng1249 2017-04-19 12:36
浏览 239

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

I'm using laravel framework based on php.And Stomp+activeMQ. Here I need to send something into mq, however the message should be consumed after 180 seconds, not immediately.

Option1, I send it with a timestamp, and the consumer will check the timestamp.If interval > 180, then do something and ack().

Option1 is inefficient, for every moment the consumer is checking timestamp but very few messages are acked.

Option2, shell_exec("php send.php | at now + 3 minute"), it looks strange.

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:

        $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.

I refer to this: ActiveMq Doc, is this concerned? I don't know.Or is it OK to send 'AMQ_SCHEDULED_DELAY' in header? Because ActiveMq Doc: Stomp does not list it as a header.

Check your Message Properties The message property scheduledJobId is reserved for use by the 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.

  • 写回答

1条回答 默认 最新

  • dongyigua4468 2019-04-10 04:30
    关注

    edit activemq.xml enable broker schedulerSupport="true"

    eg.

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

    then restart your activemq server

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记