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

non-static QueueSubscriberInterface::getSubscribedQueues() #1249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andreyserdjuk
Copy link

@andreyserdjuk andreyserdjuk commented Apr 20, 2022

I propose to make this accessor non-static to allow developers build more flexible mechanism of subscription. For example I have code:

abstract class AbstractConsumer implements Processor, QueueSubscriberInterface
{
  // ....
  // ....
    public function process(Message $message, Context $context)
    {
        $event = $this->serializer->deserialize($message->getBody(), $this->eventModel(), $this->format());
        try {
            $this->doProcessEvent($event);
        } catch (OperationNotSupportedException $e) {
            return self::REJECT;
        } catch (OperationFailedException $e) {
            return self::REQUEUE;
        }

        return self::ACK;
    }

    abstract protected function eventModel(): string;

    abstract protected function doProcessEvent(EventInterface $event): void;

    // FYI getSubscribedQueues() is implemented by child classes
}

where getSubscribedQueues() is implemented by child classes.
In my project I want to introduce EventProcessorInterface, which can process events data mapped to eventModel() considering getSubscribedEvents(): string[]. But I cannot INJECT EventProcessorInterface to AbstractConsumer and delegate QueueSubscriberInterface::getSubscribedQueues() to EventProcessorInterface::getSubscribedEvents() because it is static method!

I propose to make this accessor non-static to allow developers build more sophisticated mechanism of subscription. For example I have code:
```php
abstract class AbstractConsumer implements Processor, QueueSubscriberInterface
{
  // ....
  // ....
    public function process(Message $message, Context $context)
    {
        $event = $this->serializer->deserialize($message->getBody(), $this->eventModel(), $this->format());
        try {
            $this->doProcessEvent($event);
        } catch (OperationNotSupportedException $e) {
            return self::REJECT;
        } catch (OperationFailedException $e) {
            return self::REQUEUE;
        }

        return self::ACK;
    }

    abstract protected function eventModel(): string;

    abstract protected function doProcessEvent(EventInterface $event): void;

    // FYI getSubscribedQueues() is implemented by child classes
}
```
where `getSubscribedQueues()` is implemented by child classes.
In my project I want to introduce `EventProcessorInterface`, which can process events data mapped to `eventModel()` considering `getSubscribedEvents(): string[]`. But I cannot INJECT `EventProcessorInterface` to `AbstractConsumer` and delegate `QueueSubscriberInterface::getSubscribedQueues()` to `EventProcessorInterface::getSubscribedEvents()` because it is static method!
@stale
Copy link

stale bot commented Sep 21, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant