• Stars
    star
    234
  • Rank 171,153 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A PHP client for the NATSio cloud messaging system.

phpnats

Travis

Master Develop
Build Status Build Status

Coverage

Master Develop
Coverage Status 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": "dev-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();

// 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.

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

You can also execute the all suites ( TDD + BDD ) with 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 lint.

There is currently three steps when we lint our code:

  • 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

License

MIT, see LICENSE

More Repositories

1

nats-mon

A realtime web based NATS monitor
JavaScript
120
star
2

gomake

Example sources for a talk about Golang & Makefiles
Makefile
29
star
3

psh

A fast, configurable and full featured bash prompt $PS1 generator in Go.
Go
8
star
4

wsgnatsd

A proxy client that adds websocket support to NATS
Go
8
star
5

qurl

Qurl is a drop-in and easy to deploy microservice who exposes an HTTP API you can use to extract content from any web page as JSON. Any information available at a given public URL can be extracted using selector queries (check examples below).
Go
7
star
6

docker-vim-tmux

Docker bash + vim + tmux
Vim Script
6
star
7

bashprompt.js

bashprompt.js is a framework and a command line tool to create your own and full featured prompt for bash.
JavaScript
5
star
8

fhost

A python module that allows you to create, list, and modify Hosts file entries
Python
5
star
9

dotfiles

My dotfiles
Shell
4
star
10

git-hub

Opinionated git and github automation tool.
Go
4
star
11

monolog-nats

A Monolog NATS handler.
PHP
3
star
12

subcmd

A Python module that implements subcommands CLI pattern.
Python
3
star
13

docker-vim-crystal

A containerized Crystal lang developer environment with Docker
Vim Script
3
star
14

timeago

Go package for time formatting based on current time (eg: "3 hours ago" or "1 day ago")
Go
2
star
15

dotvim

My vim configuration
Vim Script
2
star
16

docker-vim-rust

A containerized Rust lang developer environment with Docker
Vim Script
2
star
17

makefile-help-task

A generic Makefile help task
Shell
2
star
18

apiholdit

APIholdit is a drop-in and easy to deploy microservice who exposes an HTTP API you can use to generate placeholder images with a desired text, automatically centered and scaled.
Go
2
star
19

kvson

A simple key value object notation storage module for Golang.
Go
2
star
20

docker-alpine-dotfiles

Docker container with my personal dotfiles and dotvim installed for the user "user".
Makefile
2
star
21

jstpl

A django style and compatible template engine in javascript.
2
star
22

docker-alpine-mutt

A containerized mutt instance with docker on alpine.
Makefile
2
star
23

articles

Assorted articles
HTML
2
star
24

pulsar.js

A glowing pulsar effect in canvas
JavaScript
1
star
25

ctest

watch files in directory and run tests for them
Go
1
star
26

repejota.github.io

Source code for repejota.com website based in Hugo.
HTML
1
star
27

starfield.js

An starfield effect in javascript & canvas
JavaScript
1
star
28

tetris.js

A tetris clone
JavaScript
1
star
29

resume

My resume & cover letters
Makefile
1
star
30

silex-nats-provider

A Silex NATS provider
Makefile
1
star
31

cscanner

.
Go
1
star
32

misto

.
Go
1
star
33

droller

.
Go
1
star
34

dotmutt

My mutt dotfiles
1
star
35

go-need

.
Go
1
star
36

silex-mongo-provider

Mongo service provider for the Silex micro framework.
Makefile
1
star
37

docker-alpine-python3

A docker alpine container with python3 and pip3 installed.
Makefile
1
star
38

binaryprefix

A golang module to parse Binary Prefixes for sizing Hard disks and Memory as specified in https://en.wikipedia.org/wiki/Binary_prefix
Go
1
star