bennidi / mbassador

Powerful event-bus optimized for high throughput in multi-threaded applications. Features: Sync and Async event publication, weak/strong references, event filtering, annotation driven
MIT License
955 stars 146 forks source link

Message filtering #90

Open Chumper opened 9 years ago

Chumper commented 9 years ago

I read about the message filter, but the wiki just lists some headers. How about continuing the work there?

bennidi commented 9 years ago

Yes, I think that is a good idea. I want to redesign the structure of the entire wiki because I think it is not very well organized. But I just can't find the time to do so. Other open source projects also require time and attention.

Do you have a specific question about message filtering?

Chumper commented 9 years ago

It was just a quick shot but i wanted to make the bus kind of bi-directional.

To do that i would require some kind of message id in the message and need to watch on incoming messages for this id to detect a response, kind of a custom topic or queue for the response.

For that i would need the filters but as i havent found any documentation in the wiki and was too lazy to look into some code i dont know if that would work with the bus.

If i could dynamically create topics bi directional would be no problem as i can create a custom random id topic for the message where another handler could answer. Since all bus implementation rely on reflections and custom annotation handlers, i need to solve this with some kind of message id

bennidi commented 9 years ago

Hi, sorry for not getting back to you. It seems I somehow forgot about this issue. Are you still interested? I have the intuition the your requirement can be implemented quite easily with the functionality that is already there. If you are interested you can lay out your use case in more detail and I will see what I can do.

Chumper commented 9 years ago

Yes, even so i now use Spring Reactor i will lay out a use case for you so you can decide if the use case is common or not :) give me a few hours until i get home

message commented 9 years ago

@Chumper hope you're home and safe

Chumper commented 9 years ago

Yes, took me quite a while to get home but i will try to present you my current use case:

Currently i am writing an app with libgdx, it is a puzzle game. In the game i use the messages to send events of actions i took in the code, e.g. PuzzleCreated, PuzzleSolved, PuzzleRated and so on. In most cases this is working perfectly but in specific cases i need to react on the action.

For example after a puzzle is rated i want to transmit the rating to the server that can happen without waiting for a response.

Another use case is puzzle generation: A user can generate a puzzle on the device. After the user presses Generate i send an GeneratePuzzleIntent and will show a loading indicator on the screen. At this point i am waiting for a PuzzleGenerated event to show the generated puzzle on the screen.

In order for this to work, i need to listen on dynamic topics or wait until a message returns to the sender which is not possible at the moment.

Therefore i would appreciate a consumer i can pass to the bus which is executed after all consumers handled the message or the possibility to create a second dynamic topic where all handlers can respond to.

I used reactor http://projectreactor.io/docs/reference/#bus-request-reply in another project and i needed the request response pattern 1-2 times. It would be great if MBassador could offer something similar even with some kind of more code effort.