Skip to content

Conversation

BrechtBonte
Copy link

This makes sure messages created in listeners for other messages are handled to.

A use case:

  1. Entity1 is updated using the command_bus. This causes Entity1 to record a domain message.
  2. The HandlesRecordedMessagesMiddleware handles the message and calls the registered listener.
  3. The listener updates Entity2, which causes it record another domain message.
  4. The domain message created by Entity2 is not handled.

If this functionality was already in place, and I simply missed it, please let me know, and I'll close this PR :)

@ruudk
Copy link
Contributor

ruudk commented Jun 26, 2015

And what if there is another listener that is triggered on Entity2 and tries to record messages too? Does this work with, lets say, 10 levels deep?

@BrechtBonte
Copy link
Author

As it is now, after each iteration (first calling $next, then handling all recorded messages), it will check if any new messages were added, and if so, it will start a new iteration.

So yes, it should be able to handle multiple levels :)

@matthiasnoback
Copy link

Thanks for bringing this up. Instead of modifying existing middlewares, you should just append a new instance of HandlesRecordedMessagesMiddleware to your event bus. It will collect recorded events, hand them over to the event bus and erase them afterwards.

@BrechtBonte
Copy link
Author

Wouldn't this solution limit the possible iterations to 2, so the use case of @ruudk would no longer work?

@matthiasnoback
Copy link

As mentioned here: https://github.com/SimpleBus/MessageBus/issues/26#issuecomment-122538053 recording events inside an event subscriber isn't a good idea. You can just let the event bus handle the new event right now (in fact, it won't handle the event right-away, it will just queue it in-memory and handle it when any previous event was handled).

Closing this PR now, because I think no changes are required to the code base to enable the use cases mentioned in these issues/PRs. If you think I missed something here, please let me know!

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

Successfully merging this pull request may close these issues.

3 participants