Skip to content

olivermack/phpnats

 
 

Repository files navigation

phpnats

Travis

  • Master: Build Status
  • Develop: Build Status

Coverage

  • Master: Coverage Status
  • Develop: Coverage Status

Introduction

A PHP client for the NATS messaging system.

Requirements

Usage

Installation

Let's start by downloading composer into our project dir:

curl -O http://getcomposer.org/composer.phar
chmod +x composer.phar

Now let's tell composer about our project's dependancies, in this case, PHPNats. The way we do this is by creating a composer.json file, and placing it in the root folder of our project, right next to composer.phar

{
  "require": {
    "repejota/nats": "master"
  }
}

Let's let Composer work its magic:

php composer.phar install

Composer will download all the dependencies defined in composer.json, and prepare all the files needed to autoload them.

Basic Usage

$client = new \Nats\Connection();
$client->connect();

# Simple Publisher
$client->publish("foo", "foo bar");

# Simple Subscriber
$callback = function($payload)
{
    printf("Data: %s\r\n", $payload);
};
$client->subscribe("foo", $callback);

# Request
$client->request('sayhello', 'Marty McFly', function ($response) {
    echo $response->getBody();
});

# Responding to requests
$sid = $client->subscribe("sayhello", function ($res) {
    $res->reply("Hello, " . $res->getBody() . " !!!");
});



# Wait for 1 message
$client->wait(1);

Developer's Information

Releases

Latest stable Latest dev

Tests

Tests are in the tests folder. To run them, you need PHPUnit and execute make test.

Code Quality

We are using PHP Code Sniffer to ensure our code follow an high quality standard.

To perform an analysis of the code execute make cs.

Creators

Raül Pérez

Adrià Cidre

José Gil

Gorka López de Torre

License

MIT, see LICENSE

About

A PHP client for the NATSio cloud messaging system.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 97.0%
  • Makefile 3.0%