Skip to content

Commit

Permalink
Merge pull request #9 from tienvx/update-example-usage
Browse files Browse the repository at this point in the history
docs: Update example usage in readme
  • Loading branch information
tienvx committed Mar 28, 2024
2 parents 4fd9b91 + d5b97fe commit e8b0b23
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ composer require tienvx/pact-messenger-bundle

namespace App\MessageDispatcher;

use Symfony\Component\Messenger\Stamp\TransportNamesStamp;
use App\Message\UserCreated;
use Tienvx\Bundle\PactMessengerBundle\Service\EnvelopeCollectorInterface;
use Tienvx\Bundle\PactProviderBundle\Attribute\AsMessageDispatcher;
use Tienvx\Bundle\PactProviderBundle\Model\Message;
Expand All @@ -30,13 +30,22 @@ class UserDispatcher implements DispatcherInterface
public function dispatch(): ?Message
{
$envelope = $this->collector->getSingle(UserCreated::class);
if ($envelope) {
$transports = $envelope->last(TransportNamesStamp::class)?->getTransportNames() ?? [];

return new Message(serialize($envelope->getMessage()), 'text/plain', json_encode(['transports' => $transports]));
if (!$envelope) {
return null;
}
$message = $envelope->getMessage();
if (!$message instanceof UserCreated) {
return null;
}

return null;
return new Message(
\json_encode([
'class' => UserCreated::class,
'id' => $message->userId,
]),
'application/json',
json_encode(['contentType' => 'application/json'])
);
}
}
```
Expand Down

0 comments on commit e8b0b23

Please sign in to comment.