![]() | ||||||||||||||||||||||||
| documentation examples changes amber (jpa) ejb database ioc jmx jsf messaging quercus remoting servlet security bam queue jms/php send jms/php receive jms jca listener jms ioc listener | bam queue
Using BAM to implement a queuing service.
Messaging lets a servlet delegate processing to a batch process either on the same machine or on a separate machine. The servlet creates a message and sends it to a queue. The servlet immediately completes and when the batch process is ready, it processes the message. Messaging is therefore comprised of three main components:
In this example, the Producer is a Servlet which sends a simple message.
The Producer creates a Example: MessageServlet using BamClient
import com.caucho.bam.BamClient;
public void send()
{
BamClient client = new BamClient();
ExampleMessage message = new ExampleMessage("sample message");
client.message("consumer@", message);
client.close();
}
Example: PHP using bam_send_message
<?php
$msg = java("example.ExampleMessage", "sample message");
bam_send_message("consumer@", $msg);
?>
The Queue delivers message to the Consumer one by one. When the
Consumer finishes processing a message the Queue will deliver the next
available message. The Consumer
implements In this example, the Consumer just logs the message. Example: ExampleService
package example;
import com.caucho.bam.SimpleBamService;
import com.caucho.bam.annotation.Message;
public class ExampleService extends SimpleBamService
{
@Message
public void onMessage(String to, String from, ExampleMessage message)
{
System.out.println("Message: " + message + " from=" + from);
}
}
The PHP version of the service implements a Example: bam_queue.php
<?php
function bam_message($to, $from, $value)
{
resin_debug($value);
}
bam_dispatch();
?>
Example: resin-web.xml
<web-app xmlns="http://caucho.com/ns/resin">
<bam-service name="java-consumer"
class="example.ExampleService"/>
<bam-service name="php-consumer"
uri="caucho.php:">
<init script="WEB-INF/php/bam_queue.php"/>
</bam-service>
</web-app>
| |||||||||||||||||||||||