Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to do both Async and Synchronous events in the bus. #14

Open
basejump opened this issue Dec 4, 2017 · 9 comments
Open

Ability to do both Async and Synchronous events in the bus. #14

basejump opened this issue Dec 4, 2017 · 9 comments

Comments

@basejump
Copy link

basejump commented Dec 4, 2017

Add a buildNotificationCallableSync and a subscribeSync to make it possible to add Synchronous subscriptions listeners without the need for a Gorm AbstractPersitentEvent. This would be especially useful in easily enabling subscribers to participate in Transactions.

  • In the Eventbus in the old platform-plugin for example, there was an option to fork:false that allowed this ability.
@graemerocher
Copy link
Member

You can already subscribe GORM events synchronously by using @Listener instead of a @Subscriber

@basejump
Copy link
Author

basejump commented Dec 4, 2017

yes, but only if it's gorm event and it operate under a completely different mechanism with GormEventDispatcher. Also requires any events that you might want synchronous to be an AbstractPersitentEvent. If we can just have a buildNotificationCallableSync and a subscribeSync then it would be easy to extend and have both simliar to what is done in the SynchronousEventBus setup for testing. There are a ton of use cases for this but the biggest one would be events that are transactional and don't use GORM, specifically in lighter weight microservices.

@basejump
Copy link
Author

basejump commented Dec 4, 2017

We are using a forked version of Platform plugin and were hoping to replace it with this or at least be able to extend this, the only main thing missing from the base EventBus is a mechanism for synchronous events. The way its deisgned its also more or less locked down so we can't even add another , less than ideal solution, SynchronousEventBus as it will blow an IllegalStateException

@basejump
Copy link
Author

basejump commented Dec 4, 2017

@graemerocher We can do the work on this and issue a PR but was looking for some consensus on this.

@graemerocher
Copy link
Member

Sounds good. Contributions welcome

@basejump
Copy link
Author

basejump commented Jan 9, 2018

We could close this feature request if we were the only ones interested in it. For synchronous events that need to be in a transaction, we are leaning on Spring's built-in event support.
We inject ApplicationEventPublisher and call publisher.publishEvent(event) as well as using this events eventBus.notify(event.routingKey, event) so Asynchronous listers can be used as well. 2 calls to 2 different event buses but it works and its fast. Can use the old way of implementing their ApplicationListener or use the newer @eventlistener annotation to on the listening end.
Spring has refactored it to use generics and it performs really well.

@longwa
Copy link

longwa commented Jul 16, 2018

We are also interested in a way to subscribe to events synchronously and have them execute with the same transaction as the publisher. I was considering implementing a custom event bus that allows me to look at the subscription to see if it should be synchronous before returning the callable wrapper. I haven't really gotten to implementing it so there could be other problems with this approach.

@longwa
Copy link

longwa commented Jul 19, 2018

After implementing the same solution as @basejump I started wondering why I even needed the Grails EventBus part of it at all. It seems like the spring event handling, especially with the newer annotation support, can handle most of the sync and async needs just fine.

By adding @Async to the method, I can handle the asynchronous requirement. Also, the @EventListener(condition = ...) is nicer for specifying dynamic conditions such as regex eventId matching or just other special matching conditions.

The downside is that I don't see any call back support for handling 'replies' on the spring side, so no sendAndWait equivalent.

Are there other reasons that I might prefer using the Grails event plugin vs. the built-in spring support that I'm not considering?

Just thinking out loud really, but it seems like they have mostly overlapping functionality so I'm wondering why both.

@davebrown1975
Copy link

Was there any development to this issue? I'm in a similar position, attempting to replicate synchronous events, if nothing else I'd like to use the sendAndReceive functionality however can't find any documentation explaining how to do so.

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

No branches or pull requests

4 participants