Travis
Master | Develop |
---|---|
Coverage
Master | Develop |
---|---|
A PHP client for the NATS messaging system.
- php 5.6+
- gnatsd
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": {
"cusodede/phpnats": "~1.0.0"
}
}
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.
$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();
}
);
$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();
}
);
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
.
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.
Raül Pérez
MIT, see LICENSE
phpnats's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.