Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Triggering PHP from ActiveMQ

Background: Our current system involves two services (one written in Java, the other in PHP) that communicate with each other using HTTP callbacks. We would like to migrate from HTTP callbacks to a message-based architecture using ActiveMQ (or another, if necessary). We'll probably use STOMP to communicate between them. Eventually, the PHP service will be rewritten in Java, but that's not part of this project.

Question: How can the ActiveMQ system notify PHP that a new message has been posted to the queue that the PHP system is subscribed to? In the current system, the callback inherently calls into the PHP and triggers it. This goes away with a message-based architecture.

Possible solutions:

  • Cron regularly calls a PHP script that checks for new messages. yuck.
  • A long-running PHP process that loops and sleeps and checks for new messages. less yuck?
  • ActiveMQ calls a PHP script when a new message is posted. good, how?
  • ??
like image 421
Edward Dale Avatar asked May 27 '10 16:05

Edward Dale


1 Answers

Check out Camel. It can run within ActiveMQ or by itself. Camel creates "routes" for messages. In this case I would suggest that you leave the PHP callback URL as is, and set up a route in Camel that takes messages from the queue and posts them to the callback URL. Then you can use Stomp within PHP to send messages to ActiveMQ. Your Java code can just use JMS for both incoming and outgoing messages.

like image 100
Glenn Moss Avatar answered Sep 20 '22 03:09

Glenn Moss