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

Symfony Messenger plugin #33

Closed
mathroc opened this issue Dec 4, 2018 · 5 comments
Closed

Symfony Messenger plugin #33

mathroc opened this issue Dec 4, 2018 · 5 comments

Comments

@mathroc
Copy link
Contributor

mathroc commented Dec 4, 2018

It would be nice to have a Symfony Messenger plugin

it does not dispatch events so it needs to be a middleware instead of an event subscriber, I don't know exactly how it should be added to the messenger buses middlewares from the bundle, here is how it looks in my config:

framework:
    messenger:
        buses:
            messenger.bus.default:
                middleware:
                   - App\Messenger\ResourceCleanerMiddleware
        transports:
            amqp: '%env(MESSENGER_TRANSPORT_DSN)%'
        routing:
            '*': amqp

and the middleware :

<?php declare(strict_types=1);

namespace App\Messenger;

use LongRunning\Core\DelegatingCleaner;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
use Symfony\Component\Messenger\Middleware\StackInterface;

class ResourceCleanerMiddleware implements MiddlewareInterface
{
    /** @var DelegatingCleaner */
    private $cleaner;

    public function __construct(DelegatingCleaner $cleaner)
    {
        $this->cleaner = $cleaner;
    }

    public function handle(Envelope $envelope, StackInterface $stack): Envelope
    {
        try {
            $this->cleaner->cleanup();
            $envelope = $stack->next()->handle($envelope, $stack);
            $this->cleaner->cleanup();

            return $envelope;
        } catch (\Throwable $e) {
            $this->cleaner->cleanup();
            throw $e;
        }
    }
}
@ruudk
Copy link
Contributor

ruudk commented Dec 4, 2018

Can you create a PR to add this as a plugin?

BTW: I think there is no need to call $this->cleaner->cleanup(); before handling the command.

@mathroc
Copy link
Contributor Author

mathroc commented Dec 5, 2018

@ruudk it's suseful in case there's not been messages in a while and the connection broke

@ruudk
Copy link
Contributor

ruudk commented Dec 5, 2018

But if you always cleanup after every message, there is nothing to cleanup after a while :)

@mathroc
Copy link
Contributor Author

mathroc commented Dec 5, 2018

oh I see, connections stay closed between messages so they can't broke

@Koc
Copy link

Koc commented May 23, 2019

Not sure that we really need plugin. IMHO separate middlewares like symfony/symfony#31334 and symfony/symfony#31061 is enough

@ruudk ruudk closed this as completed Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants