Skip to content

Commit 9df787b

Browse files
authored
Merge pull request #205 from php-enqueue/dsn-get-rid-of-two-slashes
[BC Break][dsn] replace xxx:// to xxx:
2 parents a8129bb + 240f932 commit 9df787b

38 files changed

+195
-143
lines changed

Diff for: 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

Diff for: 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

Diff for: 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+
```

Diff for: 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'

Diff for: 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');

Diff for: docs/transport/amqp.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ use Enqueue\AmqpExt\AmqpConnectionFactory;
3232
$connectionFactory = new AmqpConnectionFactory();
3333

3434
// same as above
35-
$connectionFactory = new AmqpConnectionFactory('amqp://');
35+
$factory = new AmqpConnectionFactory('amqp:');
3636

3737
// same as above
38-
$connectionFactory = new AmqpConnectionFactory([]);
38+
$factory = new AmqpConnectionFactory([]);
3939

4040
// connect to AMQP broker at example.com
41-
$connectionFactory = new AmqpConnectionFactory([
41+
$factory = new AmqpConnectionFactory([
4242
'host' => 'example.com',
4343
'port' => 1000,
4444
'vhost' => '/',
@@ -48,9 +48,13 @@ $connectionFactory = new AmqpConnectionFactory([
4848
]);
4949

5050
// same as above but given as DSN string
51-
$connectionFactory = new AmqpConnectionFactory('amqp://user:[email protected]:10000/%2f');
51+
$factory = new AmqpConnectionFactory('amqp://user:[email protected]:10000/%2f');
5252

53-
$psrContext = $connectionFactory->createContext();
53+
$psrContext = $factory->createContext();
54+
55+
// if you have enqueue/enqueue library installed you can use a function from there to create the context
56+
$psrContext = \Enqueue\dsn_to_context('amqp:');
57+
$psrContext = \Enqueue\dsn_to_context('amqp+ext:');
5458
```
5559

5660
## Declare topic.

Diff for: docs/transport/amqp_bunny.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ $ composer require enqueue/amqp-bunny
2929
use Enqueue\AmqpBunny\AmqpConnectionFactory;
3030

3131
// connects to localhost
32-
$connectionFactory = new AmqpConnectionFactory();
32+
$factory = new AmqpConnectionFactory();
3333

3434
// same as above
35-
$connectionFactory = new AmqpConnectionFactory('amqp://');
35+
$factory = new AmqpConnectionFactory('amqp:');
3636

3737
// same as above
38-
$connectionFactory = new AmqpConnectionFactory([]);
38+
$factory = new AmqpConnectionFactory([]);
3939

4040
// connect to AMQP broker at example.com
41-
$connectionFactory = new AmqpConnectionFactory([
41+
$factory = new AmqpConnectionFactory([
4242
'host' => 'example.com',
4343
'port' => 1000,
4444
'vhost' => '/',
@@ -48,9 +48,13 @@ $connectionFactory = new AmqpConnectionFactory([
4848
]);
4949

5050
// same as above but given as DSN string
51-
$connectionFactory = new AmqpConnectionFactory('amqp://user:[email protected]:10000/%2f');
51+
$factory = new AmqpConnectionFactory('amqp://user:[email protected]:10000/%2f');
5252

53-
$psrContext = $connectionFactory->createContext();
53+
$psrContext = $factory->createContext();
54+
55+
// if you have enqueue/enqueue library installed you can use a function from there to create the context
56+
$psrContext = \Enqueue\dsn_to_context('amqp:');
57+
$psrContext = \Enqueue\dsn_to_context('amqp+bunny:');
5458
```
5559

5660
## Declare topic.

Diff for: docs/transport/amqp_lib.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ $ composer require enqueue/amqp-lib
2929
use Enqueue\AmqpLib\AmqpConnectionFactory;
3030

3131
// connects to localhost
32-
$connectionFactory = new AmqpConnectionFactory();
32+
$factory = new AmqpConnectionFactory();
3333

3434
// same as above
35-
$connectionFactory = new AmqpConnectionFactory('amqp://');
35+
$factory = new AmqpConnectionFactory('amqp:');
3636

3737
// same as above
38-
$connectionFactory = new AmqpConnectionFactory([]);
38+
$factory = new AmqpConnectionFactory([]);
3939

4040
// connect to AMQP broker at example.com
41-
$connectionFactory = new AmqpConnectionFactory([
41+
$factory = new AmqpConnectionFactory([
4242
'host' => 'example.com',
4343
'port' => 1000,
4444
'vhost' => '/',
@@ -48,9 +48,13 @@ $connectionFactory = new AmqpConnectionFactory([
4848
]);
4949

5050
// same as above but given as DSN string
51-
$connectionFactory = new AmqpConnectionFactory('amqp://user:[email protected]:10000/%2f');
51+
$factory = new AmqpConnectionFactory('amqp://user:[email protected]:10000/%2f');
5252

53-
$psrContext = $connectionFactory->createContext();
53+
$psrContext = $factory->createContext();
54+
55+
// if you have enqueue/enqueue library installed you can use a function from there to create the context
56+
$psrContext = \Enqueue\dsn_to_context('amqp:');
57+
$psrContext = \Enqueue\dsn_to_context('amqp+lib:');
5458
```
5559

5660
## Declare topic.

Diff for: docs/transport/dbal.md

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ use Enqueue\Dbal\DbalConnectionFactory;
2828

2929
$factory = new DbalConnectionFactory('mysql://user:pass@localhost:3306/mqdev');
3030

31+
// connects to localhost
32+
$factory = new DbalConnectionFactory('mysql:');
33+
3134
$psrContext = $factory->createContext();
3235
```
3336

@@ -45,6 +48,9 @@ $factory = new ManagerRegistryConnectionFactory($registry, [
4548
]);
4649

4750
$psrContext = $factory->createContext();
51+
52+
// if you have enqueue/enqueue library installed you can use a function from there to create the context
53+
$psrContext = \Enqueue\dsn_to_context('mysql:');
4854
```
4955

5056
## Init database

Diff for: docs/transport/filesystem.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use Enqueue\Fs\FsConnectionFactory;
2929
$connectionFactory = new FsConnectionFactory();
3030

3131
// same as above
32-
$connectionFactory = new FsConnectionFactory('file://');
32+
$connectionFactory = new FsConnectionFactory('file:');
3333

3434
// stores in custom folder
3535
$connectionFactory = new FsConnectionFactory('/path/to/queue/dir');
@@ -47,6 +47,9 @@ $connectionFactory = new FsConnectionFactory([
4747
]);
4848

4949
$psrContext = $connectionFactory->createContext();
50+
51+
// if you have enqueue/enqueue library installed you can use a function from there to create the context
52+
$psrContext = \Enqueue\dsn_to_context('file:');
5053
```
5154

5255
## Send message to topic

Diff for: docs/transport/gearman.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use Enqueue\Gearman\GearmanConnectionFactory;
2626
$factory = new GearmanConnectionFactory();
2727

2828
// same as above
29-
$factory = new GearmanConnectionFactory('gearman://');
29+
$factory = new GearmanConnectionFactory('gearman:');
3030

3131
// connects to example host and port 5555
3232
$factory = new GearmanConnectionFactory('gearman://example:5555');
@@ -36,6 +36,11 @@ $factory = new GearmanConnectionFactory([
3636
'host' => 'example',
3737
'port' => 5555
3838
]);
39+
40+
$psrContext = $factory->createContext();
41+
42+
// if you have enqueue/enqueue library installed you can use a function from there to create the context
43+
$psrContext = \Enqueue\dsn_to_context('gearman:');
3944
```
4045

4146
## Send message to topic

Diff for: docs/transport/gps.md

+6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ putenv('PUBSUB_EMULATOR_HOST=http://localhost:8900');
2727

2828
$connectionFactory = new GpsConnectionFactory();
2929

30+
// save as above
31+
$connectionFactory = new GpsConnectionFactory('gps:');
32+
3033
$psrContext = $connectionFactory->createContext();
34+
35+
// if you have enqueue/enqueue library installed you can use a function from there to create the context
36+
$psrContext = \Enqueue\dsn_to_context('gps:');
3137
```
3238

3339
## Send message to topic

Diff for: docs/transport/kafka.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use Enqueue\RdKafka\RdKafkaConnectionFactory;
2525
$connectionFactory = new RdKafkaConnectionFactory();
2626

2727
// same as above
28-
$connectionFactory = new RdKafkaConnectionFactory('rdkafka://');
28+
$connectionFactory = new RdKafkaConnectionFactory('kafka:');
2929

3030
// same as above
3131
$connectionFactory = new RdKafkaConnectionFactory([]);
@@ -43,6 +43,9 @@ $connectionFactory = new RdKafkaConnectionFactory([
4343
]);
4444

4545
$psrContext = $connectionFactory->createContext();
46+
47+
// if you have enqueue/enqueue library installed you can use a function from there to create the context
48+
$psrContext = \Enqueue\dsn_to_context('kafka:');
4649
```
4750

4851
## Send message to topic

0 commit comments

Comments
 (0)