By Matthias Noback, Cliff Odijk, Ruud Kamphuis
simplebus / simplebus Goto Github PK
View Code? Open in Web Editor NEWMain repository of SimpleBus
Home Page: http://docs.simplebus.io/
License: MIT License
Main repository of SimpleBus
Home Page: http://docs.simplebus.io/
License: MIT License
By Matthias Noback, Cliff Odijk, Ruud Kamphuis
At the moment al the code is in the root of the project maybe we should move this to the src
directory?
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?
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
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
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.
In order to use bundle "SimpleBusEventBusBundle" you also need to enable "SimpleBusCommandBusBundle"
What is the reason for this dependency? If it's needed, the docs on http://simplebus.github.io/SymfonyBridge/doc/event_bus_bundle.html should be updated that the bundle requires the SimpleBusCommandBusBundle as well.
Could you make it possible to view changes between releases?
Trying to open SimpleBus/message-bus@v6.0.0...v3.1.0 I get a message:
There isn’t anything to compare.
v6.0.0 and v3.1.0 are entirely different commit histories.
In case of this repository, there are only Tags for v6.
As I see from code of logging middleware
https://github.com/SimpleBus/SimpleBus/blob/master/Component/MessageBus/src/Logging/LoggingMiddleware.php
it doesn't logs failures until command handled. Is it expected behavior? How to log failed handling?
And non-relevant question: how it possible requeue message with some delay for later processing?
http://docs.simplebus.io/en/latest/Symfony/upgrade-guide.html
I don’t see anything for 4-5, can I just upgrade if we run php 7.1 and symfony 3.4?
As discussed in #89 (comment) when Ocramius/ProxyManager#628 is merged we can remove this
https://github.com/SimpleBus/SimpleBus/blob/master/packages/symfony-bridge/composer.json#L28-L34
We now do a manual split from time to time to the different packages. We need to automated this and maybe Github actions can help us with that.
The package that we use now is this
https://github.com/dflydev/git-subsplit
They also have a github webhook
https://github.com/dflydev/dflydev-git-subsplit-github-webhook
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?
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.
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
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
.
I can provide a PR, if needed.
Interface \Doctrine\ORM\Proxy\Proxy
is going to be removed which we use here
https://github.com/SimpleBus/SimpleBus/blob/master/packages/doctrine-orm-bridge/src/EventListener/CollectsEventsFromEntities.php#L67-L76
@deprecated 2.7 This interface is being removed from the ORM and won't have any replacement, proxies will no longer implement it.
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!!
I got a composer conflict saying that SimpleBus/asynchronous-bundle:^6.0 min stability is not compatible with my project min stability level.
https://github.com/SimpleBus/asynchronous-bundle/blob/v6.0.0/composer.json#L54
Is it supposed to be like that?
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).
Stated in this issue we need to be able to setup multiple Entity Manager names to flush
References
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. :)
in
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.
If somebody wants to pick this up:
vendor/bin/phpstan
and fix all / most errors.I tried to install this symfony bridge in my project and it was not as trivial as I'd expect.
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?
As discussed in #89 (comment) when schmittjoh/JMSSerializerBundle#819 is merged we can remove this case
https://github.com/SimpleBus/SimpleBus/blob/master/.github/workflows/tests.yaml#L62-L64
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
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;
Do you think it's a good fix without risk of any breaking changes?
Have a nice evening :)
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?
According to this: https://github.com/SimpleBus/SymfonyBridge/issues/66 and this https://github.com/SimpleBus/SymfonyBridge/blob/master/src/DoctrineOrmBridgeBundle.php#L41
DoctrineORMBridge should have require:
proxy-manager-bridge
Coz after update packages composer prompt:
In order to use bundle \"DoctrineOrmBridgeBundle\" you need to require \"symfo ", "!! ny/proxy-manager-bridge\" package.
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)?
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
Available 3 version
https://github.com/schmittjoh/serializer
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.