Skip to content

Commit 25c3f41

Browse files
committed
[dsn] fix tests. clean up docs.
1 parent f4ef7a8 commit 25c3f41

12 files changed

+75
-74
lines changed

docs/bundle/quick_tour.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ It adds easy to use [configuration layer](config_reference.md), register service
66
## Install
77

88
```bash
9-
$ composer require enqueue/enqueue-bundle enqueue/amqp-ext
9+
$ composer require enqueue/enqueue-bundle enqueue/amqp-ext # or enqueue/amqp-bunny, enqueue/amqp-lib
1010
```
1111

1212
_**Note**: You could use not only AMQP transport but other available: STOMP, Amazon SQS, Redis, Filesystem, Doctrine DBAL and others._
@@ -47,7 +47,7 @@ First, you have to configure a transport layer and set one to be default.
4747

4848
enqueue:
4949
transport:
50-
default: "amqp://"
50+
default: "amqp:"
5151
client: ~
5252
```
5353

docs/client/quick_tour.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use Enqueue\SimpleClient\SimpleClient;
2222

2323
include __DIR__.'/vendor/autoload.php';
2424

25-
$client = new SimpleClient('amqp://');
25+
$client = new SimpleClient('amqp:');
2626
```
2727

2828
## Produce message

docs/client/rpc_call.md

+51-50
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,14 @@
11
# Client. RPC call
22

33
The client's [quick tour](quick_tour.md) describes how to get the client object.
4-
Here we'll use `Enqueue\SimpleClient\SimpleClient` though it is not required.
5-
You can get all that stuff from manually built client or get objects from a container (Symfony).
4+
Here we'll show you how to use Enqueue Client to perform a [RPC call](https://en.wikipedia.org/wiki/Remote_procedure_call).
5+
You can do it by defining a command which returns something.
66

7-
The simple client could be created like this:
7+
## The consumer side
88

9-
## The client side
9+
On the consumer side we have to register a command processor which computes the result and send it back to the sender.
10+
Pay attention that you have to add reply extension. It wont work without it.
1011

11-
There is a handy class RpcClient shipped with the client component.
12-
It allows you to easily perform [RPC calls](https://en.wikipedia.org/wiki/Remote_procedure_call).
13-
It send a message and wait for a reply.
14-
15-
```php
16-
<?php
17-
use Enqueue\Client\RpcClient;
18-
use Enqueue\SimpleClient\SimpleClient;
19-
20-
$client = new SimpleClient('amqp://');
21-
22-
$rpcClient = new RpcClient($client->getProducer(), $context);
23-
24-
$replyMessage = $rpcClient->call('greeting_topic', 'Hi Thomas!', 5);
25-
```
26-
27-
You can perform several requests asynchronously with `callAsync` and request replays later.
28-
29-
```php
30-
<?php
31-
use Enqueue\Client\RpcClient;
32-
use Enqueue\SimpleClient\SimpleClient;
33-
34-
$client = new SimpleClient('amqp://');
35-
36-
$rpcClient = new RpcClient($client->getProducer(), $context);
37-
38-
$promises = [];
39-
$promises[] = $rpcClient->callAsync('greeting_topic', 'Hi Thomas!', 5);
40-
$promises[] = $rpcClient->callAsync('greeting_topic', 'Hi Thomas!', 5);
41-
$promises[] = $rpcClient->callAsync('greeting_topic', 'Hi Thomas!', 5);
42-
$promises[] = $rpcClient->callAsync('greeting_topic', 'Hi Thomas!', 5);
43-
44-
$replyMessages = [];
45-
foreach ($promises as $promise) {
46-
$replyMessages[] = $promise->receive();
47-
}
48-
```
49-
50-
## The server side
51-
52-
On the server side you may register a processor which returns a result object with a reply message set.
5312
Of course it is possible to implement rpc server side based on transport classes only. That would require a bit more work to do.
5413

5514
```php
@@ -60,19 +19,61 @@ use Interop\Queue\PsrContext;
6019
use Enqueue\Consumption\Result;
6120
use Enqueue\Consumption\ChainExtension;
6221
use Enqueue\Consumption\Extension\ReplyExtension;
22+
use Enqueue\Client\Config;
6323
use Enqueue\SimpleClient\SimpleClient;
6424

6525
/** @var \Interop\Queue\PsrContext $context */
6626

67-
$client = new SimpleClient('amqp://');
27+
// composer require enqueue/amqp-ext # or enqueue/amqp-bunny, enqueue/amqp-lib
28+
$client = new SimpleClient('amqp:');
6829

69-
$client->bind('greeting_topic', 'greeting_processor', function (PsrMessage $message, PsrContext $context) use (&$requestMessage) {
70-
echo $message->getBody();
30+
$client->bind(Config::COMMAND_TOPIC, 'square', function (PsrMessage $message, PsrContext $context) use (&$requestMessage) {
31+
$number = (int) $message->getBody();
7132

72-
return Result::reply($context->createMessage('Hi there! I am John.'));
33+
return Result::reply($context->createMessage($number ^ 2));
7334
});
7435

7536
$client->consume(new ChainExtension([new ReplyExtension()]));
7637
```
7738

7839
[back to index](../index.md)
40+
41+
## The sender side
42+
43+
On the sender's side we need a client which send a command and wait for reply messages.
44+
45+
```php
46+
<?php
47+
use Enqueue\SimpleClient\SimpleClient;
48+
49+
$client = new SimpleClient('amqp:');
50+
51+
echo $client->sendCommand('square', 5, true)->receive(5000 /* 5 sec */)->getBody();
52+
```
53+
54+
You can perform several requests asynchronously with `sendCommand` and ask for replays later.
55+
56+
```php
57+
<?php
58+
use Enqueue\SimpleClient\SimpleClient;
59+
60+
$client = new SimpleClient('amqp:');
61+
62+
/** @var \Enqueue\Rpc\Promise[] $promises */
63+
$promises = [];
64+
$promises[] = $client->sendCommand('square', 5, true);
65+
$promises[] = $client->sendCommand('square', 10, true);
66+
$promises[] = $client->sendCommand('square', 7, true);
67+
$promises[] = $client->sendCommand('square', 12, true);
68+
69+
$replyMessages = [];
70+
while ($promises) {
71+
foreach ($promises as $index => $promise) {
72+
if ($replyMessage = $promise->receiveNoWait()) {
73+
$replyMessages[$index] = $replyMessage;
74+
75+
unset($promises[$index]);
76+
}
77+
}
78+
}
79+
```

docs/laravel/queues.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ return [
7070
'connection_factory_class' => \Enqueue\AmqpBunny\AmqpConnectionFactory::class,
7171

7272
// connects to localhost
73-
'dsn' => 'amqp://',
73+
'dsn' => 'amqp:',
7474

7575
// could be "rabbitmq_dlx", "rabbitmq_delay_plugin", instance of DelayStrategy interface or null
7676
// 'delay_strategy' => 'rabbitmq_dlx'

docs/quick_tour.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ use Enqueue\SimpleClient\SimpleClient;
171171
use Interop\Queue\PsrMessage;
172172

173173
// composer require enqueue/amqp-ext
174-
$client = new SimpleClient('amqp://');
174+
$client = new SimpleClient('amqp:');
175175

176176
// composer require enqueue/fs
177177
$client = new SimpleClient('file://foo/bar');
@@ -197,8 +197,8 @@ use Enqueue\Client\Config;
197197
use Enqueue\Consumption\Extension\ReplyExtension;
198198
use Enqueue\Consumption\Result;
199199

200-
// composer require enqueue/amqp-ext
201-
$client = new SimpleClient('amqp://');
200+
// composer require enqueue/amqp-ext # or enqueue/amqp-bunny or enqueue/amqp-lib
201+
$client = new SimpleClient('amqp:');
202202

203203
// composer require enqueue/fs
204204
$client = new SimpleClient('file://foo/bar');

pkg/amqp-bunny/Tests/AmqpConnectionFactoryConfigTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static function provideConfigs()
148148
];
149149

150150
yield [
151-
'amqp://',
151+
'amqp:',
152152
[
153153
'host' => 'localhost',
154154
'port' => 5672,

pkg/amqp-ext/Tests/AmqpConnectionFactoryConfigTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public static function provideConfigs()
158158
];
159159

160160
yield [
161-
'amqp://',
161+
'amqp:',
162162
[
163163
'host' => 'localhost',
164164
'port' => 5672,

pkg/amqp-lib/Tests/AmqpConnectionFactoryConfigTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public static function provideConfigs()
198198
];
199199

200200
yield [
201-
'amqp://',
201+
'amqp:',
202202
[
203203
'host' => 'localhost',
204204
'port' => 5672,

pkg/enqueue/Symfony/DefaultTransportFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function addConfiguration(ArrayNodeDefinition $builder)
5858
}
5959

6060
if (empty($v)) {
61-
return ['dsn' => 'null://'];
61+
return ['dsn' => 'null:'];
6262
}
6363

6464
if (is_string($v)) {

pkg/enqueue/Tests/Functions/DsnToContextFunctionTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ public function testReturnsExpectedFactoryInstance($dsn, $expectedFactoryClass)
5252

5353
public static function provideDSNs()
5454
{
55-
yield ['amqp://', AmqpContext::class];
55+
yield ['amqp:', AmqpContext::class];
5656

5757
yield ['amqp://user:pass@foo/vhost', AmqpContext::class];
5858

59-
yield ['file://', FsContext::class];
59+
yield ['file:', FsContext::class];
6060

6161
yield ['file://'.sys_get_temp_dir(), FsContext::class];
6262

63-
yield ['null://', NullContext::class];
63+
yield ['null:', NullContext::class];
6464

6565
yield ['redis:', RedisContext::class];
6666

pkg/enqueue/Tests/Symfony/DefaultTransportFactoryTest.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ public function testShouldSetNullTransportByDefault()
8282
$processor = new Processor();
8383

8484
$config = $processor->process($tb->buildTree(), [null]);
85-
$this->assertEquals(['dsn' => 'null://'], $config);
85+
$this->assertEquals(['dsn' => 'null:'], $config);
8686

8787
$config = $processor->process($tb->buildTree(), ['']);
88-
$this->assertEquals(['dsn' => 'null://'], $config);
88+
$this->assertEquals(['dsn' => 'null:'], $config);
8989
}
9090

9191
public function testThrowIfNeitherDsnNorAliasConfigured()
@@ -250,19 +250,19 @@ public function testShouldCreateDriverFromDsn($dsn, $expectedName)
250250

251251
public static function provideDSNs()
252252
{
253-
yield ['amqp+ext://', 'default_amqp_ext'];
253+
yield ['amqp+ext:', 'default_amqp_ext'];
254254

255255
yield ['amqp+lib:', 'default_amqp_lib'];
256256

257-
yield ['amqp+bunny://', 'default_amqp_bunny'];
257+
yield ['amqp+bunny:', 'default_amqp_bunny'];
258258

259-
yield ['null://', 'default_null'];
259+
yield ['null:', 'default_null'];
260260

261-
yield ['file://', 'default_fs'];
261+
yield ['file:', 'default_fs'];
262262

263-
yield ['mysql://', 'default_dbal'];
263+
yield ['mysql:', 'default_dbal'];
264264

265-
yield ['pgsql://', 'default_dbal'];
265+
yield ['pgsql:', 'default_dbal'];
266266

267267
yield ['gps:', 'default_gps'];
268268

pkg/simple-client/SimpleClient.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ final class SimpleClient
3737
/**
3838
* The config could be a transport DSN (string) or an array, here's an example of a few DSNs:.
3939
*
40-
* amqp://
40+
* amqp:
4141
* amqp://guest:guest@localhost:5672/%2f?lazy=1&persisted=1
4242
* file://foo/bar/
43-
* null://
43+
* null:
4444
*
4545
* or an array, the most simple:
4646
*

0 commit comments

Comments
 (0)