Skip to content

[BC Break][dsn] replace xxx:// to xxx: #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/bundle/quick_tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ It adds easy to use [configuration layer](config_reference.md), register service
## Install

```bash
$ composer require enqueue/enqueue-bundle enqueue/amqp-ext
$ composer require enqueue/enqueue-bundle enqueue/amqp-ext # or enqueue/amqp-bunny, enqueue/amqp-lib
```

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

enqueue:
transport:
default: "amqp://"
default: "amqp:"
client: ~
```

Expand Down
2 changes: 1 addition & 1 deletion docs/client/quick_tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use Enqueue\SimpleClient\SimpleClient;

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

$client = new SimpleClient('amqp://');
$client = new SimpleClient('amqp:');
```

## Produce message
Expand Down
101 changes: 51 additions & 50 deletions docs/client/rpc_call.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,14 @@
# Client. RPC call

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

The simple client could be created like this:
## The consumer side

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

There is a handy class RpcClient shipped with the client component.
It allows you to easily perform [RPC calls](https://en.wikipedia.org/wiki/Remote_procedure_call).
It send a message and wait for a reply.

```php
<?php
use Enqueue\Client\RpcClient;
use Enqueue\SimpleClient\SimpleClient;

$client = new SimpleClient('amqp://');

$rpcClient = new RpcClient($client->getProducer(), $context);

$replyMessage = $rpcClient->call('greeting_topic', 'Hi Thomas!', 5);
```

You can perform several requests asynchronously with `callAsync` and request replays later.

```php
<?php
use Enqueue\Client\RpcClient;
use Enqueue\SimpleClient\SimpleClient;

$client = new SimpleClient('amqp://');

$rpcClient = new RpcClient($client->getProducer(), $context);

$promises = [];
$promises[] = $rpcClient->callAsync('greeting_topic', 'Hi Thomas!', 5);
$promises[] = $rpcClient->callAsync('greeting_topic', 'Hi Thomas!', 5);
$promises[] = $rpcClient->callAsync('greeting_topic', 'Hi Thomas!', 5);
$promises[] = $rpcClient->callAsync('greeting_topic', 'Hi Thomas!', 5);

$replyMessages = [];
foreach ($promises as $promise) {
$replyMessages[] = $promise->receive();
}
```

## The server side

On the server side you may register a processor which returns a result object with a reply message set.
Of course it is possible to implement rpc server side based on transport classes only. That would require a bit more work to do.

```php
Expand All @@ -60,19 +19,61 @@ use Interop\Queue\PsrContext;
use Enqueue\Consumption\Result;
use Enqueue\Consumption\ChainExtension;
use Enqueue\Consumption\Extension\ReplyExtension;
use Enqueue\Client\Config;
use Enqueue\SimpleClient\SimpleClient;

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

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

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

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

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

[back to index](../index.md)

## The sender side

On the sender's side we need a client which send a command and wait for reply messages.

```php
<?php
use Enqueue\SimpleClient\SimpleClient;

$client = new SimpleClient('amqp:');

echo $client->sendCommand('square', 5, true)->receive(5000 /* 5 sec */)->getBody();
```

You can perform several requests asynchronously with `sendCommand` and ask for replays later.

```php
<?php
use Enqueue\SimpleClient\SimpleClient;

$client = new SimpleClient('amqp:');

/** @var \Enqueue\Rpc\Promise[] $promises */
$promises = [];
$promises[] = $client->sendCommand('square', 5, true);
$promises[] = $client->sendCommand('square', 10, true);
$promises[] = $client->sendCommand('square', 7, true);
$promises[] = $client->sendCommand('square', 12, true);

$replyMessages = [];
while ($promises) {
foreach ($promises as $index => $promise) {
if ($replyMessage = $promise->receiveNoWait()) {
$replyMessages[$index] = $replyMessage;

unset($promises[$index]);
}
}
}
```
2 changes: 1 addition & 1 deletion docs/laravel/queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ return [
'connection_factory_class' => \Enqueue\AmqpBunny\AmqpConnectionFactory::class,

// connects to localhost
'dsn' => 'amqp://',
'dsn' => 'amqp:',

// could be "rabbitmq_dlx", "rabbitmq_delay_plugin", instance of DelayStrategy interface or null
// 'delay_strategy' => 'rabbitmq_dlx'
Expand Down
6 changes: 3 additions & 3 deletions docs/quick_tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ use Enqueue\SimpleClient\SimpleClient;
use Interop\Queue\PsrMessage;

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

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

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

// composer require enqueue/fs
$client = new SimpleClient('file://foo/bar');
Expand Down
14 changes: 9 additions & 5 deletions docs/transport/amqp.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ use Enqueue\AmqpExt\AmqpConnectionFactory;
$connectionFactory = new AmqpConnectionFactory();

// same as above
$connectionFactory = new AmqpConnectionFactory('amqp://');
$factory = new AmqpConnectionFactory('amqp:');

// same as above
$connectionFactory = new AmqpConnectionFactory([]);
$factory = new AmqpConnectionFactory([]);

// connect to AMQP broker at example.com
$connectionFactory = new AmqpConnectionFactory([
$factory = new AmqpConnectionFactory([
'host' => 'example.com',
'port' => 1000,
'vhost' => '/',
Expand All @@ -48,9 +48,13 @@ $connectionFactory = new AmqpConnectionFactory([
]);

// same as above but given as DSN string
$connectionFactory = new AmqpConnectionFactory('amqp://user:pass@example.com:10000/%2f');
$factory = new AmqpConnectionFactory('amqp://user:pass@example.com:10000/%2f');

$psrContext = $connectionFactory->createContext();
$psrContext = $factory->createContext();

// if you have enqueue/enqueue library installed you can use a function from there to create the context
$psrContext = \Enqueue\dsn_to_context('amqp:');
$psrContext = \Enqueue\dsn_to_context('amqp+ext:');
```

## Declare topic.
Expand Down
16 changes: 10 additions & 6 deletions docs/transport/amqp_bunny.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ $ composer require enqueue/amqp-bunny
use Enqueue\AmqpBunny\AmqpConnectionFactory;

// connects to localhost
$connectionFactory = new AmqpConnectionFactory();
$factory = new AmqpConnectionFactory();

// same as above
$connectionFactory = new AmqpConnectionFactory('amqp://');
$factory = new AmqpConnectionFactory('amqp:');

// same as above
$connectionFactory = new AmqpConnectionFactory([]);
$factory = new AmqpConnectionFactory([]);

// connect to AMQP broker at example.com
$connectionFactory = new AmqpConnectionFactory([
$factory = new AmqpConnectionFactory([
'host' => 'example.com',
'port' => 1000,
'vhost' => '/',
Expand All @@ -48,9 +48,13 @@ $connectionFactory = new AmqpConnectionFactory([
]);

// same as above but given as DSN string
$connectionFactory = new AmqpConnectionFactory('amqp://user:pass@example.com:10000/%2f');
$factory = new AmqpConnectionFactory('amqp://user:pass@example.com:10000/%2f');

$psrContext = $connectionFactory->createContext();
$psrContext = $factory->createContext();

// if you have enqueue/enqueue library installed you can use a function from there to create the context
$psrContext = \Enqueue\dsn_to_context('amqp:');
$psrContext = \Enqueue\dsn_to_context('amqp+bunny:');
```

## Declare topic.
Expand Down
16 changes: 10 additions & 6 deletions docs/transport/amqp_lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ $ composer require enqueue/amqp-lib
use Enqueue\AmqpLib\AmqpConnectionFactory;

// connects to localhost
$connectionFactory = new AmqpConnectionFactory();
$factory = new AmqpConnectionFactory();

// same as above
$connectionFactory = new AmqpConnectionFactory('amqp://');
$factory = new AmqpConnectionFactory('amqp:');

// same as above
$connectionFactory = new AmqpConnectionFactory([]);
$factory = new AmqpConnectionFactory([]);

// connect to AMQP broker at example.com
$connectionFactory = new AmqpConnectionFactory([
$factory = new AmqpConnectionFactory([
'host' => 'example.com',
'port' => 1000,
'vhost' => '/',
Expand All @@ -48,9 +48,13 @@ $connectionFactory = new AmqpConnectionFactory([
]);

// same as above but given as DSN string
$connectionFactory = new AmqpConnectionFactory('amqp://user:pass@example.com:10000/%2f');
$factory = new AmqpConnectionFactory('amqp://user:pass@example.com:10000/%2f');

$psrContext = $connectionFactory->createContext();
$psrContext = $factory->createContext();

// if you have enqueue/enqueue library installed you can use a function from there to create the context
$psrContext = \Enqueue\dsn_to_context('amqp:');
$psrContext = \Enqueue\dsn_to_context('amqp+lib:');
```

## Declare topic.
Expand Down
6 changes: 6 additions & 0 deletions docs/transport/dbal.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ use Enqueue\Dbal\DbalConnectionFactory;

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

// connects to localhost
$factory = new DbalConnectionFactory('mysql:');

$psrContext = $factory->createContext();
```

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

$psrContext = $factory->createContext();

// if you have enqueue/enqueue library installed you can use a function from there to create the context
$psrContext = \Enqueue\dsn_to_context('mysql:');
```

## Init database
Expand Down
5 changes: 4 additions & 1 deletion docs/transport/filesystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use Enqueue\Fs\FsConnectionFactory;
$connectionFactory = new FsConnectionFactory();

// same as above
$connectionFactory = new FsConnectionFactory('file://');
$connectionFactory = new FsConnectionFactory('file:');

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

$psrContext = $connectionFactory->createContext();

// if you have enqueue/enqueue library installed you can use a function from there to create the context
$psrContext = \Enqueue\dsn_to_context('file:');
```

## Send message to topic
Expand Down
7 changes: 6 additions & 1 deletion docs/transport/gearman.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use Enqueue\Gearman\GearmanConnectionFactory;
$factory = new GearmanConnectionFactory();

// same as above
$factory = new GearmanConnectionFactory('gearman://');
$factory = new GearmanConnectionFactory('gearman:');

// connects to example host and port 5555
$factory = new GearmanConnectionFactory('gearman://example:5555');
Expand All @@ -36,6 +36,11 @@ $factory = new GearmanConnectionFactory([
'host' => 'example',
'port' => 5555
]);

$psrContext = $factory->createContext();

// if you have enqueue/enqueue library installed you can use a function from there to create the context
$psrContext = \Enqueue\dsn_to_context('gearman:');
```

## Send message to topic
Expand Down
6 changes: 6 additions & 0 deletions docs/transport/gps.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ putenv('PUBSUB_EMULATOR_HOST=http://localhost:8900');

$connectionFactory = new GpsConnectionFactory();

// save as above
$connectionFactory = new GpsConnectionFactory('gps:');

$psrContext = $connectionFactory->createContext();

// if you have enqueue/enqueue library installed you can use a function from there to create the context
$psrContext = \Enqueue\dsn_to_context('gps:');
```

## Send message to topic
Expand Down
5 changes: 4 additions & 1 deletion docs/transport/kafka.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use Enqueue\RdKafka\RdKafkaConnectionFactory;
$connectionFactory = new RdKafkaConnectionFactory();

// same as above
$connectionFactory = new RdKafkaConnectionFactory('rdkafka://');
$connectionFactory = new RdKafkaConnectionFactory('kafka:');

// same as above
$connectionFactory = new RdKafkaConnectionFactory([]);
Expand All @@ -43,6 +43,9 @@ $connectionFactory = new RdKafkaConnectionFactory([
]);

$psrContext = $connectionFactory->createContext();

// if you have enqueue/enqueue library installed you can use a function from there to create the context
$psrContext = \Enqueue\dsn_to_context('kafka:');
```

## Send message to topic
Expand Down
Loading