问题
Is it possible to subscribe from PHP via Stomp to an ActiveMQ broker and access the JobScheduler (and subsequently remove a scheduled message by its jobId)?
I have a set of scheduled messages for a queue "PROD" produced from 2 web servers, and upon the occurrence of an event on the same web server (aware of jobIds), would like to remove them from the JobScheduler so that the consumers (written in Java and located on multiple remote servers) don't receive them.
I'm using ActiveMQ broker v5.9.1, and Stomp to connect to the broker form PHP.
回答1:
You can manage scheduled jobs in ActiveMQ over STOMP. I've written about this before showing how to do it using the ActiveMQ Java client but the principle is the same. You can send messages with specific headers set that will operate on the scheduled messages.
To remove a message that was scheduled using the Java client you'd do the following:
Message remove = session.createMessage();
remove.setStringProperty(ScheduledMessage.AMQ_SCHEDULER_ACTION,
ScheduledMessage.AMQ_SCHEDULER_ACTION_REMOVE);
remove.setStringProperty(ScheduledMessage.AMQ_SCHEDULED_ID,
scheduled.getStringProperty(ScheduledMessage.AMQ_SCHEDULED_ID));
producer.send(remove);
The full set of message property values that can be used when working with the scheduler are documented here, in STOMP just use the string literal of each as the message property.
来源:https://stackoverflow.com/questions/32297897/activemq-jobscheduler-remove-message