Skip to content

Commit db8b85e

Browse files
authored
Merge pull request #365 from php-enqueue/doc-client-send-method-description
[client][skip ci] Explain meaning of sendEvent, sendCommand methods.
2 parents 12719eb + 545bc5e commit db8b85e

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

docs/client/quick_tour.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ $ composer require enqueue/simple-client enqueue/amqp-ext
1616

1717
## Configure
1818

19+
The code below shows how to use simple client with AMQP transport. There are other [supported brokers](supported_brokers.md).
20+
1921
```php
2022
<?php
2123
use Enqueue\SimpleClient\SimpleClient;
@@ -27,25 +29,56 @@ $client = new SimpleClient('amqp:');
2729

2830
## Produce message
2931

32+
There two types of message a client can produce: events and commands.
33+
Events are used to notify others about something, in other words it is an implementation of [publish-subscribe pattern](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern), sometimes called "fire-and-forget" too.
34+
With events there is no way to get a reply as a producer is not aware of any subscribed consumers.
35+
Commands are used to request a job to be done. It is an implementation of one-to-one messaging pattern.
36+
A producer can request a reply from the consumer though it is up to the consumer whether send it or not.
37+
38+
Commands work inside the app [scope](message_examples.md#scope) where events work inside the app scope as well as on [message bus](message_bus.md) scope.
39+
40+
Send event examples:
41+
3042
```php
3143
<?php
3244

3345
/** @var \Enqueue\SimpleClient\SimpleClient $client */
3446

35-
$client->send('a_bar_topic', 'aMessageData');
47+
$client->setupBroker();
48+
49+
$client->sendEvent('user_updated', 'aMessageData');
3650

3751
// or an array
3852

39-
$client->send('a_bar_topic', ['foo', 'bar']);
53+
$client->sendEvent('order_price_calculated', ['foo', 'bar']);
4054

4155
// or an json serializable object
42-
$client->send('a_bar_topic', new class() implements \JsonSerializable {
56+
$client->sendEvent('user_activated', new class() implements \JsonSerializable {
4357
public function jsonSerialize() {
4458
return ['foo', 'bar'];
4559
}
4660
});
4761
```
4862

63+
Send command examples:
64+
65+
```php
66+
<?php
67+
68+
/** @var \Enqueue\SimpleClient\SimpleClient $client */
69+
70+
$client->setupBroker();
71+
72+
// accepts same type of arguments as sendEvent method
73+
$client->sendCommand('calculate_statistics', 'aMessageData');
74+
75+
$reply = $client->sendCommand('build_category_tree', 'aMessageData', true);
76+
77+
$replyMessage = $reply->receive(5000); // wait for reply for 5 seconds
78+
79+
$replyMessage->getBody();
80+
```
81+
4982
## Consume messages
5083

5184
```php

docs/client/supported_brokers.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Client. Supported brokers
22

3+
Here's the list of transports supported by Enqueue Client:
4+
5+
| Transport | Package | DSN |
6+
|:-------------------:|:----------------------------------------------------------:|:-------------------------------:|
7+
| AMQP, RabbitMQ | [enqueue/amqp-bunny](../transport/amqp_bunny.md) | amqp: amqp+bunny: |
8+
| AMQP, RabbitMQ | [enqueue/amqp-lib](../transport/amqp_lib.md) | amqp: amqp+lib: |
9+
| AMQP, RabbitMQ | [enqueue/amqp-ext](../transport/amqp.md) | amqp: amqp+ext: |
10+
| Doctrine DBAL | [enqueue/dbal](../transport/dbal.md) | mysql: pgsql: pdo_pgsql etc |
11+
| Filesystem | [enqueue/fs](../transport/fs.md) | file:///foo/bar |
12+
| Google PubSub | [enqueue/gps](../transport/gps.md) | gps: |
13+
| Redis | [enqueue/gps](../transport/redis.md) | redis: |
14+
| Amazon SQS | [enqueue/sqs](../transport/sqs.md) | sqs: |
15+
| STOMP, RabbitMQ | [enqueue/stomp](../transport/stomp.md) | stomp: |
16+
| Null | [enqueue/null](../transport/null.md) | null: |
17+
318
Here's the list of protocols and Client features supported by them
419

520
| Protocol | Priority | Delay | Expiration | Setup broker | Message bus |
@@ -11,7 +26,8 @@ Here's the list of protocols and Client features supported by them
1126
| Filesystem | No | No | No | Yes | No |
1227
| Redis | No | No | No | Not needed | No |
1328
| Doctrine DBAL | Yes | Yes | No | Yes | No |
14-
| AWS SQS | No | Yes | No | Yes | Not impl |
29+
| Amazon SQS | No | Yes | No | Yes | Not impl |
30+
| Google PubSub | Not impl | Not impl | Not impl | Yes | Not impl |
1531

1632
* \* Possible if a RabbitMQ delay plugin is installed.
1733
* \*\* Possible if topics (exchanges) are configured on broker side manually.

docs/quick_tour.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ $replyMessage = $promise->receive(2000); // 2 sec
233233
$client->consume([new ReplyExtension()]);
234234
```
235235

236+
Read more about events and commands [here](client/quick_tour.md#produce-message).
237+
236238
## Cli commands
237239

238240
The library provides handy commands out of the box.

pkg/simple-client/SimpleClient.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public function sendEvent($topic, $message)
125125
}
126126

127127
/**
128+
* @deprecated since 0.8.18 and will be removed in 0.9. Use sendEvent method instead
129+
*
128130
* @param string $topic
129131
* @param string|array $message
130132
* @param bool $setupBroker

0 commit comments

Comments
 (0)