Skip to content
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

Dispatching two events when a message is sent & handled #30650

Merged
merged 1 commit into from Mar 23, 2019

Conversation

Projects
None yet
4 participants
@weaverryan
Copy link
Member

commented Mar 22, 2019

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets none
License MIT
Doc PR TODO

Alternative to #30646. This uses a more generic system, so you could do anything when a message is sent. The main use-case is when a message is dispatched by a 3rd party.

I didn't try to add exhaustive events everywhere: I added an event for a very specific use-case:

When a message is dispatched by a 3rd party, being able to add stamps (e.g. DelayStamp or a future AmqpRoutingKeyStamp before the message is sent. Example:

class MailerMessageSendToTransportEventSubscriber implements EventSubscriberInterface
{
    public function onSendMessage(SendMessageToTransportsEvent $event)
    {
        $envelope = $event->getEnvelope();
        if (!$envelope->getMessage() instanceof SomeMailerMessage) {
            return;
        }

        $event->setEnvelope($envelope->with(new AmpqRoutingKeyStamp('mailer-route')));
    }

    public static function getSubscribedEvents()
    {
        return [SendMessageToTransportsEvent::class => 'onSendMessage'];
    }
}

Along with #30557, we will now have the following events, regarding async messages:

  • Event when a message is sent to transports (this PR)
  • Event when a message is received from transport, but before handling it
  • Event when a message is received from transport and after handling it

@weaverryan weaverryan requested a review from sroze as a code owner Mar 22, 2019

@weaverryan weaverryan force-pushed the weaverryan:middleware-events branch from 8083077 to 49d3c46 Mar 22, 2019

@weaverryan weaverryan referenced this pull request Mar 22, 2019

Closed

[Messenger] Making it Shine #30540

30 of 36 tasks complete

@weaverryan weaverryan force-pushed the weaverryan:middleware-events branch from 49d3c46 to 04fcf90 Mar 23, 2019

@weaverryan weaverryan force-pushed the weaverryan:middleware-events branch from 04fcf90 to a7ad1b4 Mar 23, 2019

@weaverryan

This comment has been minimized.

Copy link
Member Author

commented Mar 23, 2019

This should be ready to go

@sroze

sroze approved these changes Mar 23, 2019

@fabpot

fabpot approved these changes Mar 23, 2019

@fabpot

This comment has been minimized.

Copy link
Member

commented Mar 23, 2019

Thank you @weaverryan.

@fabpot fabpot merged commit a7ad1b4 into symfony:master Mar 23, 2019

2 of 3 checks passed

continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details

fabpot added a commit that referenced this pull request Mar 23, 2019

feature #30650 Dispatching two events when a message is sent & handle…
…d (weaverryan)

This PR was merged into the 4.3-dev branch.

Discussion
----------

Dispatching two events when a message is sent & handled

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none
| License       | MIT
| Doc PR        | TODO

Alternative to #30646. This uses a more generic system, so you could do anything when a message is sent. The main use-case is when a message is dispatched by a 3rd party.

I didn't try to add *exhaustive* events everywhere: I added an event for a very specific use-case:

When a message is dispatched by a 3rd party, being able to add stamps (e.g. `DelayStamp` or a future `AmqpRoutingKeyStamp` before the message is sent. Example:

```php
class MailerMessageSendToTransportEventSubscriber implements EventSubscriberInterface
{
    public function onSendMessage(SendMessageToTransportsEvent $event)
    {
        $envelope = $event->getEnvelope();
        if (!$envelope->getMessage() instanceof SomeMailerMessage) {
            return;
        }

        $event->setEnvelope($envelope->with(new AmpqRoutingKeyStamp('mailer-route')));
    }

    public static function getSubscribedEvents()
    {
        return [SendMessageToTransportsEvent::class => 'onSendMessage'];
    }
}
```

Along with #30557, we will now have the following events, regarding async messages:
* Event when a message is sent to transports (this PR)
* Event when a message is received from transport, but before handling it
* Event when a message is received from transport and after handling it

Commits
-------

a7ad1b4 Dispatching two events when a message is sent & handled

@weaverryan weaverryan referenced this pull request Mar 28, 2019

Open

[Messenger][4.3] Tracker for changes #11236

1 of 25 tasks complete

@fabpot fabpot referenced this pull request May 9, 2019

Merged

Release v4.3.0-BETA1 #31435

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.