views:

105

answers:

3

Background

I have two services that need to communicate with each other over a message queue. One is a legacy service written in PHP and the other is in Java. Sooner than later, the PHP service will be rewritten in Java. The current way they communicate with each other is to write to a shared database, which the other service polls. This is what I'm trying to get away from and replace with a message queue.

Problem

The communication I'm working on right now is from the PHP service to the Java service. It needs to send a relatively complex object (strings and and integers and lists and maps of strings and integers). Ideally, the solution would be workable in PHP and ideal in Java, as that's going to be the legacy of this project.

Possible Solutions

    1.
A: 

There is a STOMP client for PHP,

http://pecl.php.net/package/stomp

ZZ Coder
Yup, there's also a pure PHP library at http://stomp.fusesource.org/ which seems to work better with ActiveMQ. Using Stomp is a given, but how to use it is where I'm hitting a wall.
scompt.com
A: 

In my view you should keep component interactions free from specific implementations. ActiveMQ is buggy and many systems removed it in favour of RabbitMQ or Sun OpenMQ. You have to avoid coding "send message" routines in PHP, create "SendMessage" servlet instead, and use curl to post JSON-encoded message. The servlet will then use connection factory etc. With a little overhead you will free PHP component from any mq-server specific code. You may use TextMessage with JSON'ed load, encoding and decoding it easily with Jackson.

ilya b.
I have no problem with MQ specific code in the PHP. It's legacy code anyway. Besides, MQ provides some nice guarantees for persistence, durability, delivery, etc. Creating a servlet and using curl, etc is not the right solution in this situation.
scompt.com
+1  A: 

The solution that I've come up with is to enqueue messages from PHP/Stomp using the jms-json-object transformation. The messages are specially crafted JSON such that when they are dequeued in Java using readObject, they can be reconstructed to a full object using XStream. This reconstruction happens internal to ActiveMQ and I just have to make sure that the necessary aliases and converters are in place. When we finally replace the PHP component with Java, sending a message will just be a matter of using writeObject.

scompt.com