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 import com.caucho.bam.LocalActorClient; public void send() { LocalActorClient client = new LocalActorClient(); ExampleMessage message = new ExampleMessage("sample message"); client.message("consumer@", message); client.close(); } <?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. package example; import com.caucho.bam.SimpleActor; import com.caucho.bam.Message; public class ExampleService extends SimpleActor; { @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 <?php function bam_message($to, $from, $value) { resin_debug($value); } bam_dispatch(); ?> <web-app xmlns="http://caucho.com/ns/resin"> <example:ExampleService> <resin:BamService name="java-consumer"/> </example:ExampleService> <bam-service name="php-consumer" uri="caucho.php:"> <init script="WEB-INF/php/bam_queue.php"/> </bam-service> </web-app>
|