简体   繁体   中英

PHP+Stomp+ActiveMq, “AMQ_SCHEDULED_DELAY” not working

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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