Giter VIP home page Giter VIP logo

simplebus's Introduction

simplebus's People

Contributors

bgaleotti avatar brammm avatar caciobanu avatar cafferata avatar cmodijk avatar dependabot[bot] avatar garak avatar geoffroyr avatar gjuric avatar holtkamp avatar ifdattic avatar jaspernbrouwer avatar jdreesen avatar kbond avatar krizon avatar lakiboy avatar magnusnordlander avatar maks-rafalko avatar markredeman avatar matthiasnoback avatar nyholm avatar prgtw avatar ramondelafuente avatar renatomefi avatar ruudk avatar scaytrase avatar sroze avatar tnajanssen avatar tomasvotruba avatar xcorter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

simplebus's Issues

EventBus Subscribers not working with notify method

When I use the EventBus in a Symfony 4 app with autowiring, I have to use __invoke() for the method to be called in the subscriber. However, the docs state that I should be able to use either __invoke or notify.

Is this wrong in the documentation, or is there some configuration I'm missing.

My service declaration:

    App\Domain\Subscriber\:
        resource: '../src/Domain/Subscriber'
        tags: [event_subscriber]
        public: true

And my event subscriber (this is edited for brevity):

<?php

namespace App\Domain\Subscriber\Project\Issue;

use App\Domain\Event\Project\Issue\IssueCreatedEvent;

class IssueCreatedEventSubscriber
{
    public function __notify(IssueCreatedEvent $event): void
    {
        // ... code that does stuff when event is received
    }
}

This works, but if I change public function __invoke(IssueCreatedEvent $event): void to public function notify(IssueCreatedEvent $event): void, the event subscriber is no longer called.

Digging in a little deeper, it looks to be something with how the EventBusBridge compiler pass is looking for Event Subscribers. When I run bin/console debug:container IssueCreatedEventSubscriber, I can see the event_subscriber tag, but if I change the method to notify, the tag is no longer applied to the service.

I'm not sure what the difference is between the EventBusBridge compiler pass and the CommandBusBridge compiler pass. My command handlers work with both __invoke and handle.

When I look in SimpleBusEventBusBundle.php, I see the following:

$container->addCompilerPass(
    new RegisterSubscribers(
        'simple_bus.event_bus.event_subscribers_collection',
        'event_subscriber',
        'subscribes_to'
    )
);

I tried changing __invoke to either subscribes_to or subscribesTo, but neither worked.

So, is this a bug, an error in documentation (and I have to use __invoke), or am I messing something up?

And if it is an error in documentation, why can we use handle in command handlers, but not notify in event subscribers?

The future of SimpleBus

Back in september of 2016 @matthiasnoback contacted me about taking over the maintenance of the SimpleBus project. The biggest reason for this was that we @JCID are using SimpleBus in most of our recent projects and as so are using it a lot an have a lot of experience running it in production. SimpleBus itself was back then and still right now a very stable project with not a lot of work and has the flexibility to be extended and changed in your own project as needed. This means that for me there is not a lot to do with the project itself the only thing i need to do is answer a question from time to time.

For some time I felt that I was alone in maintaining the project but also using the project there was not a lot of movement in the issue tracker so for me the project went down in how much time i was spending on the project on a week by week base eventually @ruudk joint me as maintainer to allow us to move forward. The biggest thing for maintenance back then was that we had a lot of small repositories which meant that making even a small changed required a few pull requests and coordination in merging these issues. So we decided to merge al these package into 1 repository and use sub split to keep the package still in sync. @ruudk and i joint up back in december of 2017 to make this all happen.

But not long there after @sroze contacted me about a pull request that he created to get a Messenger component going for the Symfony project. Back then and since then i did not find the time to respond to that and i'm sorry for that. But in the meantime the component was merged and evolved a lot within the walls of Symfony project. I personally believe this is a very good thing that we now have a very large community that is the Symfony community in maintaining the component.

But what is there for SimpleBus to do now? We have a amazing new component which is inspired by this project a lot. I don't have a lot of time these days in maintaining the project so if you ask me we should stop active development on the SimpleBus project. What I propose to do is create page in the documentation on how to migrate to the Messenger component maybe @sroze or @Nyholm can help us with this. After that I think we should make a statement in de README that the project is not no longer actively developed anymore and we only support the project up to Symfony 4.0 as the messenger component is Symfony 4.1 and higher.

I would like to here any feedback on this and if someone want's to take over from me we can also discuss this.

More details

Sequentially Asynchronous EventBus for relations 1 Event - N Subscribers

Hello,

In my app I have many subscribers to one asynchronous event and they are executed sequentially, so if one fails, the next it won't be processed.
Is there a way, using a middleware or anything else to avoid this behavior?
I do not understand why a subscriber will not be executed if the previous fails.
As I can see doing tests, all the subscribers are being executed in the same "transaction/thread".

Thanks

Decide what to do with the BernardBundleBridge

A lot of tests are failing for BernardBundleBridge and the Bernard project seems to be at a stand still we need to decide if we still want to keep supporting it.

  • Remove code from mono repository #29
  • Mark project as deprecated
  • Archive project on github

CQRS + EV and User ID propagation

Hi,

This is not a bug report, but a question about messages architecture and data propagation.
Let say I have a command that creates an entity (let say CreateBankAccount).
The command handler will create the bank account and private events generated by the entity itself will be dispatched. Nothing realy exiting here.

Now I would like to know who (user and console command) sent the command.
At the moment, I just register the user ID/console command name when I create the command.

But how to propagate that user ID?
For now, every single entity method that generate an event needs that user ID:

  • public function __construct(string $accountId, string $displayName, string $userId)
  • public function withdraw(int $amount, string $userId)
  • public function setName(string $displayName, string $userId)
  • ...

It works great... but it looks like some good practices are broken here. When you change an entity name, you expect a method like setName(string $displayName). Not more, not less.

Do you know a better way to propagate that user ID from the command to the dispatched events?

Listener service is not found after upgrading Symfony 4.3.11 -> 4.4.5

Hi!

I've upgraded Symfony from 4.3.11 to 4.4.5, simple-bus/symfony-bridge to 5.4.0. Now I am facing an issue with listener services. They are declared public, have the necessary tag. But they are no more found, throwing exception

Service "App\MyBundle\Listener\MyEventListenerListener" not found: the container inside "Symfony\Component\DependencyInjection\Argument\ServiceLocator" is a smaller service locator that is empty...

Here is how the listener is defined:

<service id="App\MyBundle\Listener\MyEventListenerListener" public="true">
    <tag name="event_subscriber" subscribes_to="App\MyBundle\Event\MyEvent" method="handle" />
</service>

It worked fine in Symfony 4.3.11. Please advice. Thank you in advance.

Incorrect exception class catch in middleware - a short story why my consumer sometimes doesn't work

So in default configuration FinishesHandlingMessageBeforeHandlingNext middleware is enabled, which assures us that the next message will be processed only after the current one has finished. Let us check how it looks like:

$this->queue[] = $message;

        if (!$this->isHandling) {
            $this->isHandling = true;

            while ($message = array_shift($this->queue)) {
                try {
                    $next($message);
                } catch (Exception $exception) {
                    $this->isHandling = false;

                    throw $exception;
                }
            }

            $this->isHandling = false;
        }

The problem is that from PHP 7 Exception implement another interface Throwable. So when your consumer fails with (for example) TypeError then this middleware will badly mark the isHandling flag and put your next message on a queue.

In practice, this meant that from time to time messages were processed ultra-fast which made me very curious why, it turned out that these messages are not correctly processed, so I managed to get to this place.

Fixed in #71

Split SymfonyBridge in 3 different packages

  • DoctrineORMBridgeBundle
  • CommandBusBundle
  • EventBusBundle

Main reason to do this now is that we are already on the verge of creating a new major version and this allows us to force the ProxyManager dependecie for DoctrineOrmBridgeBundle.

Add readme

  • For main repository
  • For all sub repositories

Logging middleware before Transactional

Hi Matthias!

I've been playing this week with the shiny new version and everything works like a charm, thanks! However, I was wondering why the Transactional Doctrine middleware is registered before the Logging middleware, I would prefer the transaction to be "as close as possible" to the real work done inside the command. If somehow the logging failed that would mean rolling back the transaction too, which is not desirable IMHO

[2015-05-29 12:11:21] doctrine.DEBUG: "START TRANSACTION" [] []
[2015-05-29 12:11:21] command_bus.DEBUG: Started handling a message {"message":"[object](Ulabox\Inventory\Application\Command\Sku\LinkWithProduct: {})"} []

array(5) {
  [0] =>
  string(71) "simple_bus.command_bus.finishes_command_before_handling_next_middleware"
  [1] =>
  string(56) "simple_bus.event_bus.handles_recorded_mesages_middleware"
  [2] =>
  string(64) "simple_bus.doctrine_orm_bridge.wraps_next_command_in_transaction"
  [3] =>
  string(41) "simple_bus.command_bus.logging_middleware"
  [4] =>
  string(62) "simple_bus.command_bus.delegates_to_message_handler_middleware"
}

Thanks!!

Add support for PHP 8

Hello 🚀

I think all repositories here are not usable with PHP 8.

Composer tells me this:

image

My composer.json requires PHP 8 and I'm using these versions:

"simple-bus/doctrine-orm-bridge": "^5.1",
"simple-bus/symfony-bridge": "^5.4",

Is it possible to add PHP 8 support?

Thank you :)

Missing recipe

I tried to install simple-bus/rabbitmq-bundle-bridge with Symfony 4 (and so with Flex).

I'm getting this error:

The child node "object_serializer_service_id" at path "simple_bus_asynchronous" must be configured.

Likely, a recipe is missing here (maybe more than one).

[Request] - Lazy command handler middlewares

I've been wanting to use middlewares for command object validation and also for authorization. The problem is that their usage gets heavier and heavier as you add more since middlewares aren't lazily loaded.

I've come up with a quick solution that works for me using a new decorator class and a compiler pass. It adds a bit of magic but i don't have to manually deal with defining chains of nested decorators in yaml.

Basically, it replaces the original command handler with a new handler that contains a reference to the id of the original handler and id's of the middlewares you wish to apply to that specific handler. It will lazily instantiate the middlewares and original handler as needed.

Would anyone be interested in a me making a pull request? If it doesn't really align with the ideologies, no worries! Just throwing the idea out there. :)

Here's a gist of what i've done.

Allow to disable default FinishesHandlingMessageBeforeHandlingNext

in

simple_bus.command_bus.finishes_command_before_handling_next_middleware:

FinishesHandlingMessageBeforeHandlingNext is enabled by default, which forces us to use "serialized" execution of the commands. But in our case we put commands to the bus inside the handler and expect that all handlers fail in chain if the inner handler fails, as well as we expect the command to be executed synchronously without delay, as the next code expect the modified state if command executed successfully.

Currently we have to disable this middleware using DI hacks with removing tags from service in order to achieve it.

Dispatching events outside of a command

We use SimpleBus inside a legacy application which does not use commands an handlers for everything but we do have events inside of our doctrine entity's and if i trigger the events inside a entity outside a command handler the events are not dispatched. Is there a way to manually dispatch the events inside of the event recorder queue?

TypeError with Doctrine\Common\Persistence\ManagerRegistry

Hello :)

Happy valentine's day!

I'm currently facing this error below using "simple-bus/doctrine-orm-bridge": "^5.1".

TypeError: SimpleBus\DoctrineORMBridge\MessageBus\WrapsMessageHandlingInTransaction::__construct(): Argument #1 ($managerRegistry) must be of type Doctrine\Common\Persistence\ManagerRegistry, Doctrine\Bundle\DoctrineBundle\Registry given, called in /var/www/html/var/test/cache/ContainerMEBxOdm/getSimpleBus_DoctrineOrmBridge_WrapsNextCommandInTransactionService.php on line 23

vendor/doctrine/doctrine-bundle/Resources/config/dbal.xml
image

The class seems not to exist anymore in Doctrine and I think it's now Doctrine\Persistence\ManagerRegistry

So I've tried to change the use statement inside of WrapsMessageHandlingInTransaction to use that interface and works properly

use Doctrine\Persistence\ManagerRegistry;
  • PHP 8.0.1
  • Symfony 5.2.3
  • Doctrine Dbal 2.12.1
  • Doctrine Orm 2.8.1
  • Doctrine Persistence 2.1.0
  • Doctrine Common 3.1.1
  • Doctrine Bundle 2.2.3
  • SimpleBus Doctrine Orm Bridge 5.1.0

Do you think it's a good fix without risk of any breaking changes?

Have a nice evening :)

Disable read only repositories issues

Hi guys!

Maybe we should disable the possibility for all read only repositories and update the README.md with a link to the main repo ?

Do you need help to move issues, if that is a necessary step?

Command Handlers as private services

Hi,

I created some commands and command handlers that are all public services.
But in fact I never use these services and only use the command_bus service to send my commands:

$command = new FooBarCommand(...);
$commandBus->handle($command);

But when I set my command handlers as private, I get the following error:

The "FooBarCommandHandler" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.

Is there any when to mark those commands as private and still continue to use the command_bus service (public)?

File could not be downloaded: failed to open stream:

Symfony 4.0.2
Vagrant + Homestead
Windows 10 Pro

$ composer require simple-bus/simple-bus
The "http://packagist.org/p/provider-2015%249a252938f0616ff57cb6ed93c4ff6058afa50f095f82893466076a7cd61987ee.json" file could not be downloaded: failed to open stream: A connection attempt failed because the connected party did n
ot properly respond after a period of time, or established connection failed because connected host has failed to respond.

http://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date
....

So simple-bus package can not be installed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.