2017 © Pedro PelĆ”ez
 

library phpnats2

A nats.io client in PHP

image

vladitot/phpnats2

A nats.io client in PHP

  • Tuesday, July 31, 2018
  • by vladitot
  • Repository
  • 1 Watchers
  • 1 Stars
  • 247 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 16 Versions
  • 752 % Grown

The README.md

phpnats

Travis, (*1)

Master Develop
Build Status Build Status

Coverage, (*2)

Master Develop
Coverage Status Coverage Status

Introduction

A PHP client for the NATS messaging system., (*3)

Requirements

Usage

Installation

Let's start by downloading composer into our project dir:, (*4)

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, (*5)

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

Let's let Composer work its magic:, (*6)

php composer.phar install

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

Basic Usage

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

// Publish Subscribe

// Simple Subscriber.
$client->subscribe(
    'foo',
    function ($message) {
        printf("Data: %s\r\n", $message->getBody());
    }
);

// Simple Publisher.
$client->publish('foo', 'Marty McFly');

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

// Request Response

// Responding to requests.
$sid = $client->subscribe(
    'sayhello',
    function ($message) {
        $message->reply('Reply: Hello, '.$message->getBody().' !!!');
    }
);

// Request.
$client->request(
    'sayhello',
    'Marty McFly',
    function ($message) {
        echo $message->getBody();
    }
);

Encoded Connections

$encoder = new \Nats\Encoders\JSONEncoder();
$options = new \Nats\ConnectionOptions();
$client = new \Nats\EncodedConnection($options, $encoder);
$client->connect();

// Publish Subscribe

// Simple Subscriber.
$client->subscribe(
    'foo',
    function ($payload) {
        printf("Data: %s\r\n", $payload->getBody()[1]);
    }
);

// Simple Publisher.
$client->publish(
    'foo',
    [
     'Marty',
     'McFly',
    ]
);

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

// Request Response

// Responding to requests.
$sid = $client->subscribe(
    'sayhello',
    function ($message) {
        $message->reply('Reply: Hello, '.$message->getBody()[1].' !!!');
    }
);

// Request.
$client->request(
    'sayhello',
    [
     'Marty',
     'McFly',
    ],
    function ($message) {
        echo $message->getBody();
    }
);

Developer's Information

Releases

Tests

Tests are in the tests folder. To run them, you need PHPUnit and execute make test-tdd., (*10)

We also have a BDD test suite under the spec folder. To run the suite, you need PHPSpec and execute make test-bdd., (*11)

You can also execute the all suites ( TDD + BDD ) with make test., (*12)

Code Quality

We are using PHP Code Sniffer to ensure our code follow an high quality standard., (*13)

To perform an analysis of the code execute make lint., (*14)

There is currently three steps when we lint our code:, (*15)

  • First we lint with php itself php -l
  • Then we lint with PSR2 standard
  • And finally we lint with a custom ruleset.xml that checks dockblocks and different performance tips.

Creators

Raül Pérez, (*16)

License

MIT, see LICENSE, (*17)

The Versions

31/07 2018
31/07 2018
30/07 2018
25/07 2018
25/07 2018
25/07 2018
24/07 2018
02/07 2018
02/07 2018
27/06 2018
26/06 2018
24/06 2018
08/06 2018
17/05 2018
08/05 2018
07/05 2018