| |||||||||||||||||||||||||||
Find this tutorial in: /usr/local/resin/webapps/resin-doc/jms/tutorial/php-queue-receive
Try the Tutorial
Quercus offers a simplified messaging interface built upon JMS. This functionality makes it possible to send and receive messages using either the Resin JMS implementation or any other messaging service with a JMS implementation. Many features of JMS are designed for message-driven services which make sense in the Java world, but are not appropriate for PHP. This tutorial focuses receiving messages in a non-blocking way.
This example uses two queues: an "ad queue" and a "control queue". The PHP script removes advertisements from the ad queue using the receive() method. This method is non-blocking - if there are no advertisements, the method will return FALSE instead of waiting for a new advertisement. Whenever the PHP script removes an advertisement from the ad queue, it signals a Java message driven bean (MDB) to add another ad by sending an empty message to the control queue.
The programming model of the Quercus JMS interface is first to create a connection to a queue by instantiating a JMSQueue object. To create a JMSQueue object, pass in the JNDI name of the JMS queue to be used. JMSQueue objects have two methods: send() and receive(). The example above shows how to use both methods.
JMS requires that two resources be set up: A
ConnectionFactory and a Queue. Both are
configured in
This example uses two queues, jms/AdQueue and jms/ControlQueue.
The complete configuration is in
|