| ||||||||||||||||||
Resin 3.1 Documentation Examples Changes Quercus Database Amber EJB SOA/ESB IoC JMS Servlet JMX Hessian Security JMS/PHP Send JMS/PHP Receive JMS Listener JMS IOC Listener |
Files in this tutorial
Using JMS in QuercusQuercus 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. Receiving JMS messages from a PHP script
This example uses two queues: an "ad queue" and a "control queue".
The PHP script removes advertisements from the ad queue using the
$ad_queue = new JMSQueue("jms/AdQueue"); $control_queue = new JMSQueue("jms/ControlQueue"); if (! $ad_queue) { echo "Unable to get ad queue!\n"; } elseif (! $control_queue) { echo "Unable to get control queue!\n"; } else { $ad = $ad_queue->receive(); if ($ad == null) { echo "No ads available on the queue\n"; } else { echo "$ad"; } if (! $control_queue->send(0)) { echo "Unable to send control message\n"; } }
The programming model of the Quercus JMS interface is first to create
a connection to a queue by instantiating a Configuring JMS for PHP and Java
JMS requires that two resources be set up: A
<resource jndi-name="jms/ConnectionFactory" type='com.caucho.jms.ConnectionFactoryImpl' />
This example uses two queues, <resource jndi-name="jms/AdQueue" type='com.caucho.jms.memory.MemoryQueue' /> <resource jndi-name="jms/ControlQueue" type='com.caucho.jms.memory.MemoryQueue' /> The complete configuration is in WEB-INF/resin-web.xml.
|