ASPit - Totally ASP JSit - Totally JavaScript
Search PHPit

Use this textbox to search for articles on PHPit. Seperate keywords with a space.

Advertisements

How to ‘JMS’ PHP

(Page 2 out of 3)

The MantaRay RMI API should be enabled in the configuration of MantaRay, and MantaRay should be started as a standalone before running any PHP scripts:

  1. Download and unzip the MantaRay messaging toolkit from http://sourceforge.net/projects/mantaray/
  2. Enable the RMI API by setting enable_rmi_api to true in the default_config.params configuration file.
  3. Enable the creation of an RMI registry by setting create_rmi_registry to true in the default_config.params configuration file, unless you are using an external RMI registry.
  4. Set rmi_registry_port to the port that the RMI registry will listen to, in the default_config.params configuration file.
  5. Set rmi_registry_host_name to the IP address or hostname of the computer where the RMI registry is located (if the registry is local, use �localhost�).
  6. Start MantaRay by running the org.mr.MantaStandAlone class or by running standalone.bat.

To create an instance of the PHP messaging API, a PHP script should include messaging.php like this:

include('./libraries/messaging.php');
$msg = new messaging('//localhost',10005);

The parameters passed at instantiation are the host name and port number of the MantaRay RMI Registry.

The PHP messaging API includes the following functions:

function enqueue($userKey, $queueName, $message)
Sends $message (string) to a queue with name $queueName (string). $userKey (string) is the
Identifier used by the messaging bus.

function dequeue($userKey, $queueName)
Returns a string message dequeued from the queue with name $queueName (string). $userKey (string) is the identifier used by the messaging bus.

function getQueues()
Returns an array of strings that are the names of queues available on the message bus.

function getTopics()
Returns an array of strings that are the names of topics available on the message bus.

function subscribe($userKey $topicName, $messagesToCash)
Adds a listener to a given $topicName (string). The listener will receive up to $messagesToCash (number) messages. $userId (string) is the identifier used by the messaging bus; use this identifier to get messages with getMessageFromTopic(....)

function getMessageFromTopic($userKey, $topicName)
Gets the messages gathered by the listener on a given $topicName (string). $userKey (string) is the identifier used by the messaging bus used when invoking subscribe(�).

function publishMessage($userKey, $topicName, $msg)
Publishes a $msg (string) to a topic with name $topicName (string). $userKey (string) is the identifier used by the messaging bus.

In the PHPMQ download package there are several examples for both queues and topics.

« Previous: Definitions
Next: PHP / JAVA and Apache »



Leave a Reply

About the author
Dennis Pallett is the main contributor to PHPit. He owns several websites, including ASPit and Chill2Music. He is currently still studying.
Article Index
  1. Definitions
  2. Configuring MantaRay to run with PHPMQ
  3. PHP / JAVA and Apache
Bookmark Article
Download Article
PDF
Download this article as a PDF file