2017 © Pedro PelĆ”ez
 

library nats

A nats.io client in PHP

image

repejota/nats

A nats.io client in PHP

  • Saturday, June 9, 2018
  • by repejota
  • Repository
  • 12 Watchers
  • 115 Stars
  • 15,228 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 32 Forks
  • 10 Open issues
  • 34 Versions
  • 23 % 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

20/06 2017

dev-dependenci24584

dev-dependenci24584

A nats.io client in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by JosƩ Gil

25/04 2017
29/06 2015
28/06 2015

0.0.3

0.0.3.0

A nats.io client in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

28/06 2015

0.0.2

0.0.2.0

A nats.io client in PHP

  Sources   Download

MIT

The Development Requires

28/06 2015

0.0.1

0.0.1.0

A nats.io client in PHP

  Sources   Download

MIT

The Development Requires