Skip to content
Prev Previous commit
Next Next commit
Introduce the TransportInterface
  • Loading branch information
sroze authored and weaverryan committed May 9, 2018
commit 10f46eb0626613fff3b7a3ea629d1db72db94b46
34 changes: 26 additions & 8 deletions messenger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,30 +279,48 @@ Once you have written your transport's sender and receiver, you can register you
transport factory to be able to use it via a DSN in the Symfony application.

Create your Transport Factory
~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You need to give FrameworkBundle the opportunity to create your transport from a
DSN. You will need an transport factory::

use Symfony\Component\Messenger\Transport\Factory\AdapterFactoryInterface;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;
use Symfony\Component\Messenger\Transport\ReceiverInterface;
use Symfony\Component\Messenger\Transport\SenderInterface;

class YourTransportFactory implements TransportFactoryInterface
{
public function createReceiver(string $dsn, array $options): ReceiverInterface
public function createTransport(string $dsn, array $options): TransportInterface
{
return new YourReceiver(/* ... */);
return new YourTransport(/* ... */);
}

public function createSender(string $dsn, array $options): SenderInterface
public function supports(string $dsn, array $options): bool
{
return new YourSender(/* ... */);
return 0 === strpos($dsn, 'my-transport://');
}
}

public function supports(string $dsn, array $options): bool
The transport object is needs to implements the ``TransportInterface`` (which simply combine
the ``SenderInterface`` and ``ReceiverInterface``). It will look
like this::

class YourTransport implements TransportInterface
{
public function send($message) : void
{
return 0 === strpos($dsn, 'my-transport://');
// ...
}

public function receive(callable $handler) : void
{
// ...
}

public function stop() : void
{
// ...
}
}

Expand Down