FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

non-static QueueSubscriberInterface::getSubscribedQueues() by andreyserdjuk · Pull Request #1249 · php-enqueue/enqueue-dev · GitHub

non-static QueueSubscriberInterface::getSubscribedQueues() - #1249

Open
andreyserdjuk wants to merge 1 commit into
php-enqueue:masterfrom
andreyserdjuk:patch-1
Open

non-static QueueSubscriberInterface::getSubscribedQueues()#1249
andreyserdjuk wants to merge 1 commit into
php-enqueue:masterfrom
andreyserdjuk:patch-1

Conversation

andreyserdjuk commented Apr 20, 2022
edited
Loading

Copy link
Copy Markdown

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 Bot commented Sep 21, 2022

Copy link
Copy Markdown

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 Bot added the wontfix label Sep 21, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL