MigratoryData Client API for ReactPHP
Developer's Guide and Reference Manual
Developer's Guide

This guide includes the following sections:

Overview

This Application Programming Interface (API) contains all the necessary operations for connecting to a cluster of one or more MigratoryData servers, subscribing to one or more subjects, getting real-time messages for the subscribed subjects, and publishing real-time messages.

Before reading this manual, it is recommended to read MigratoryData Architecture Guide (PDF, HTML).

Creating PHP clients for MigratoryData Server

A typical API usage is as follows:

Step 1 - Include the libraries

Use the following to include the library:

   require_once '../../lib/migratorydata-client.php';

Use composer to install react event-loop and react socket. After that import the autoload.php file.

   require 'vendor/autoload.php';

Step 2 - Create react event loop and give the loop to the client

Use the API call MigratoryDataClient.setLoop() to attach the created react event loop.

Step 3 - Define a listener to get messages and status notifications

The listener should implement the MigratoryDataListener interface.

Use the API call MigratoryDataClient.setListener() to attach your listener implementation.

Step 4 - Specify where to connect to

Specify a cluster of one or more MigratoryData servers to which the Java client will connect to using the API method MigratoryDataClient.setServers(). In fact, the client will connect to only one of the MigratoryData servers in this list. But, defining two or more MigratoryData servers is recommended in order to achieve fail-over. Supposing the MigratoryData server to which the client connected goes down, then the API will automatically reconnect the client to another MigratoryData server in the list.

Step 5 - Connect to the MigratoryData cluster

Use the API method MigratoryDataClient.connect() to connect to the cluster and start receiving real-time messages from the MigratoryData cluster as well as status notifications.

Step 6 - Subscribe to subjects and publish messages

Use the API method MigratoryDataClient.subscribe() to specify interest in receiving real-time messages having as subjects the strings provided in the parameter of this API method. You can call the API method MigratoryDataClient.subscribe() at any time to subscribe to further subjects. To unsubscribe from subscribed subjects, use the API method MigratoryDataClient.unsubscribe().

Use the API method MigratoryDataClient.publish() to publish messages.

Step 7 - Handle the real-time messages and status notifications

Handle the messages received for the subscribed subjects as well as the status notifications in your listener implementation defined at Step 2 above.

Use the API method MigratoryDataClient.publish() to publish messages.

Examples

Examples built with this API are available in the folder examples of this API package; start with the README file which explains how to run them.