FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[doc] add docs for simple client. · practice-code/enqueue-dev@fac8096 · GitHub

Commit fac8096

Browse files
committed
[doc] add docs for simple client.
1 parent 0ed8ffc commit fac8096

3 files changed

Lines changed: 149 additions & 20 deletions

File tree

‎docs/client/quick_tour.md‎

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Simple client. Quick tour.
2+
3+
The simple client library takes Enqueue client classes and Symfony components and makes an easy to use client facade.
4+
It reduces the boiler plate code you have to write to start using the Enqueue client features.
5+
6+
* [Install](#install)
7+
* [Configure](#configure)
8+
* [Producer message](#produce-message)
9+
* [Consume messages](#consume-messages)
10+
11+
## Install
12+
13+
```bash
14+
$ composer require enqueue/simple-client enqueue/amqp-ext
15+
```
16+
17+
## Configure
18+
19+
```php
20+
<?php
21+
use Enqueue\SimpleClient\SimpleClient;
22+
23+
include __DIR__.'/vendor/autoload.php';
24+
25+
$client = new SimpleClient([
26+
'transport' => [
27+
'default' => 'amqp',
28+
'amqp' => [
29+
'host' => 'localhost',
30+
'port' => 5672,
31+
'vhost' => '/',
32+
'login' => 'guest',
33+
'password' => 'guest',
34+
],
35+
],
36+
'client' => [
37+
'app_name' => 'plain_php',
38+
],
39+
]);
40+
```
41+
42+
## Produce message
43+
44+
```php
45+
<?php
46+
47+
/** @var \Enqueue\SimpleClient\SimpleClient $client */
48+
49+
$client->send('a_bar_topic', 'aMessageData');
50+
51+
// or an array
52+
53+
$client->send('a_bar_topic', ['foo', 'bar']);
54+
55+
// or an json serializable object
56+
$client->send('a_bar_topic', new class() implements \JsonSerializable {
57+
public function jsonSerialize() {
58+
return ['foo', 'bar'];
59+
}
60+
});
61+
```
62+
63+
## Consume messages
64+
65+
```php
66+
<?php
67+
68+
use Enqueue\Psr\PsrMessage;
69+
70+
/** @var \Enqueue\SimpleClient\SimpleClient $client */
71+
72+
$client->bind('a_bar_topic', 'a_processor_name', function(PsrMessage $psrMessage) {
73+
// processing logic here
74+
});
75+
76+
$client->consume();
77+
```
78+
79+
## Cli commands
80+
81+
```php
82+
#!/usr/bin/env php
83+
<?php
84+
85+
// bin/enqueue.php
86+
87+
use Enqueue\Symfony\Client\ConsumeMessagesCommand;
88+
use Enqueue\Symfony\Client\Meta\QueuesCommand;
89+
use Enqueue\Symfony\Client\Meta\TopicsCommand;
90+
use Enqueue\Symfony\Client\ProduceMessageCommand;
91+
use Enqueue\Symfony\Client\SetupBrokerCommand;
92+
use Symfony\Component\Console\Application;
93+
94+
/** @var \Enqueue\SimpleClient\SimpleClient $client */
95+
96+
$application = new Application();
97+
$application->add(new SetupBrokerCommand($client->getDriver()));
98+
$application->add(new ProduceMessageCommand($client->getProducer()));
99+
$application->add(new QueuesCommand($client->getQueueMetaRegistry()));
100+
$application->add(new TopicsCommand($client->getTopicMetaRegistry()));
101+
$application->add(new ConsumeMessagesCommand(
102+
$client->getQueueConsumer(),
103+
$client->getDelegateProcessor(),
104+
$client->getQueueMetaRegistry(),
105+
$client->getDriver()
106+
));
107+
108+
$application->run();
109+
```
110+
111+
and run to see what is there:
112+
113+
```bash
114+
$ php bin/enqueue.php
115+
```
116+
117+
or consume messages
118+
119+
```bash
120+
$ php bin/enqueue.php enqueue:consume -vvv --setup-broker
121+
```
122+
123+
[back to index](../index.md)

‎docs/client/rpc_call.md‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Client. RPC call
22

3+
The client's [quick tour](quick_tour.md) describes how to get the client object.
4+
We use you followed instructions there and have instance of `Enqueue\SimpleClient\SimpleClient` in `$client` var.
35

46
## The client side
57

@@ -8,13 +10,10 @@ It allows you to easily send a message and wait for a reply.
810

911
```php
1012
<?php
11-
use Enqueue\Client\SimpleClient;
1213
use Enqueue\Client\RpcClient;
1314

14-
/** @var \Enqueue\Psr\PsrContext $context */
15-
15+
/** @var \Enqueue\SimpleClient\SimpleClient $client */
1616

17-
$client = new SimpleClient($context);
1817
$rpcClient = new RpcClient($client->getProducer(), $context);
1918

2019
$replyMessage = $rpcClient->call('greeting_topic', 'Hi Thomas!', 5);
@@ -24,13 +23,10 @@ You can perform several requests asynchronously with `callAsync` and request rep
2423

2524
```php
2625
<?php
27-
use Enqueue\Client\SimpleClient;
2826
use Enqueue\Client\RpcClient;
2927

30-
/** @var \Enqueue\Psr\PsrContext $context */
28+
/** @var \Enqueue\SimpleClient\SimpleClient $client */
3129

32-
33-
$client = new SimpleClient($context);
3430
$rpcClient = new RpcClient($client->getProducer(), $context);
3531

3632
$promises = [];
@@ -53,7 +49,6 @@ Of course it is possible to implement rpc server side based on transport classes
5349
```php
5450
<?php
5551

56-
use Enqueue\Client\SimpleClient;
5752
use Enqueue\Psr\PsrMessage;
5853
use Enqueue\Psr\PsrContext;
5954
use Enqueue\Consumption\Result;
@@ -62,7 +57,8 @@ use Enqueue\Consumption\Extension\ReplyExtension;
6257

6358
/** @var \Enqueue\Psr\PsrContext $context */
6459

65-
$client = new SimpleClient($this->context);
60+
/** @var \Enqueue\SimpleClient\SimpleClient $client */
61+
6662
$client->bind('greeting_topic', 'greeting_processor', function (PsrMessage $message, PsrContext $context) use (&$requestMessage) {
6763
echo $message->getBody();
6864

‎docs/quick_tour.md‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,30 @@ Here's an example of how you can send and consume messages.
167167

168168
```php
169169
<?php
170-
use Enqueue\Client\SimpleClient;
170+
use Enqueue\SimpleClient\SimpleClient;
171171
use Enqueue\Psr\PsrMessage;
172-
use Enqueue\Psr\PsrProcessor;
173-
174-
/** @var \Enqueue\Psr\PsrContext $psrContext */
175172

176-
$client = new SimpleClient($psrContext);
177-
$client->bind('foo_topic', 'processor_name', function (PsrMessage $message) {
178-
// process message
179-
180-
return PsrProcessor::ACK;
173+
$client = new SimpleClient([
174+
'transport' => [
175+
'default' => 'amqp',
176+
'amqp' => [
177+
'host' => 'localhost',
178+
'port' => 5672,
179+
'vhost' => '/',
180+
'login' => 'guest',
181+
'password' => 'guest',
182+
],
183+
],
184+
'client' => true,
185+
]);
186+
187+
$client->setupBroker();
188+
189+
$client->bind('a_foo_topic', 'fooProcessor', function(PsrMessage $message) {
190+
// your processing logic here
181191
});
182192

183-
$client->send('foo_topic', 'Hello there!');
193+
$client->send('a_bar_topic', 'aMessageData');
184194

185195
// in another process you can consume messages.
186196
$client->consume();

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL