Can we define a subscriber for multiple Grails events - events

I am new to the grails framework. Currently using version 4.0.12. I have one requirement where I want to subscribe to multiple grails events with a single subscriber method, for e.g.,
#Subscriber('*-*')
anyMethod () {
// TO DOs
}
How can we achieve something like above using regex or any other alternative?

Related

Use eventstore with Axon Framework 3 and Spring Boot

I'm trying to realize a simple distributed applications, and I would like to save all the events into the event store.
For this reason, as suggested in the "documentation" of Axon here, I would like to use Mysql as event store.
Since I haven't very much experience with Spring, I cannot understand how to getting it working.
I would have two separate services one for the command side and one for the query side. Since I'm planning to have more services, I would like to know how to configure them to use an external event store (not stored inside of any of these services).
For the distribution of the commands and events, I'm using RabbitMQ:
#Bean
public org.springframework.amqp.core.Exchange exchange() {
return ExchangeBuilder.fanoutExchange("AxonEvents").build();
}
#Bean
public Queue queue() {
return QueueBuilder.durable("AxonEvents").build();
}
#Bean
public Binding binding() {
return BindingBuilder.bind(queue()).to(exchange()).with("*").noargs();
}
#Autowired
public void configure(AmqpAdmin admin)
{
admin.declareExchange(exchange());
admin.declareQueue(queue());
admin.declareBinding(binding());
}
This creates the required queue on a local running RabbitMQ instance (with default username and password).
My question is: How can I configure Axon to use mysql as an event store?
As the Reference Guide currently does not specify this, I am gonna point this out here.
Currently you've roughly got two approaches you follow when distributing an Axon application or separating an Axon application into (micro) services:
Use an full open source approach
Use AxonHub / AxonDb
Taking approach 2, which you can do in a developer environment, you would only have to run AxonHub and AxonDb and configure them to your application.
That's it, your done; you can scale out your application and all the messages are routed as desired.
If you want to take route 1 however, you will have to provide several configurations
Firstly, you state you use RabbitMQ to route commands and events.
In fact, the framework does not simply allow using RabbitMQ to route commands at all. Do note it is a solution to distribute EventMessages, just not CommandMessages.
I suggest either using JGroups or Spring Cloud to route your commands in a open-source scenario (I have added links to the Reference Guide pages regarding distributing the CommandBus for JGroups and Spring Cloud).
To distribute your events, you can take three approaches:
Use a shared database for your events.
Use AMQP to send your evens to different instances.
Use Kafka to send your evens to different instances.
My personal preference when starting an application though, is to begin with one monolith and separate when necessary.
I think the term 'Evolutionary Micro Services' catches this nicely.
Any how, if you use the messaging paradigm supported by Axon to it's fullest, splitting out the Command side from the Query side after wards should be quite simple.
If you'd in addition use the AxonHub to distribute your messages, then you are practically done.
Concluding though, I did not find a very exact request from your issues.
Does this give you the required information to proceed, #Federico Ponzi?
Update
After having given it some thought, I think your solution is quite simple.
You are using Spring Boot and you want to set up your EventStore to use MySQL. For Axon to set the right EventStorageEngine (the infra component used under the covers to read/write events), you can simply add a dependency on the spring-boot-starter-data-jpa.
Axon it's auto configuration will in that scenario automatically notice that you have Spring Data JPA on your classpath, and as such will set the JpaEventStorageEngine.

How can I do sendAndReceive with Spring EventListener?

With the (meanwhile deprecated) reactor-bus from project-reactor I had the API eventBus.sendAndReceive(Event e, Consumer<?> callback).
This allowed to trigger execution by publishing an event and automatically subscribe to a response.
With Spring eventListeners I can publish another event from an EventListener method, but I am missing the feature to directly subscribe to a return value.
How do I achieve the same behaviour with spring? How do I programmaticcaly register/unregister listeners and how do I make the topics dynamic?
With Spring's ApplicationEventMulticaster you can't subscribe to a response. You probably noticed that the onApplicationEvent method returns void! The reason for this is because literally all it does is either call the Subscriber (i.e. ApplicationListener) synchronously, or runs the listener method asynchronously on an executor without returning any type of Future.
Spring's Project Reactor evolved a while ago to match the Reactive Manifesto and similar frameworks (like RxJava) more closely. Now with Spring 5 (with which Reactor comes with by default) you can use Reactor and RxJava interchangeably.
That being the case, regarding your questions:
How do I achieve the same behaviour with spring?
You use the new version of Reactor Core and the functional programming features of Flux, Mono, etc.
With Spring eventListeners I can publish another event from an
EventListener method, but I am missing the feature to directly
subscribe to a return value.
If you look at the API for Flux, you'll see that it has a fluent and functional API (in some ways similar to Java 8 streams).
Flux.just(1, 2, 3, 4)
.map(value -> value + 1)
.subscribe(subscriber::function);
This way, you can operate on your "events" (i.e. 1,2,3,4 in this example), perform an operation on what would be a "return value" for those events, and then pipe those to some subscriber operation to consume those events.
How do I programmaticcaly register/unregister listeners and how do I
make the topics dynamic?
You should take a look at this SO answer.
To register/unregister, that's something you can do with what you might call "completors" in the Reactor framework. See the take functions in the Reactor API. They will signal upstream that they basically want to be unsubscribed, and that the upstream producer should stop emitting.

How to map multiple versions of web service incoming requests to the same Java endpoint method using Spring WS

We currently use Spring's PayloadRootAnnotationMethodEndpointMapping to map incoming messages to the appropriate Java endpoints. We're going to have a new version of WSDL (with enhanced business functionality) to be made available to the user community while we're also required to continue to support the existing version of WSDL for backward compatibility.
The versioning information will be embedded in the namespaces' URNs, for examples:
urn:mycompany:myproject:mymodule:messages:1.0urn:mycompany:myproject:mymodule:messages:1.1
Since there's only a small fraction of Java methods that have changed between the old version and the new version, I was wondering what would be the best way to handle those methods that have NOT changed between the two versions in terms of endpoint mapping. In other words, how can I route the incoming messages of both versions to the same Java endpoint method?
One option I was thinking of was to write a custom Spring-ws endpoint mapping class (possibly by extending PayloadRootAnnotationMethodEndpointMapping class. But before I write any code, I'd like to check with you guys to see:
1) Are there some best practices with respect to supporting multiple versions of WSDLs by a single server side implementation?
2) Does Spring-ws have any out-of-box solutions for this type of the situations?
Thanks,
As of Spring-WS 2.2, there is a #PayloadRoots annotation which allows you to map multiple payloads to one method, like so:
#PayloadRoots({
#PayloadRoot(localPart = "Request1", namespace = "http://springframework.org/spring-ws"),
#PayloadRoot(localPart = "Request2", namespace = "http://springframework.org/spring-ws")
})
public void doIt(#RequestPayload Source payload) {
...
}
I'd also like to point you to the PayloadTransformingInterceptor, which transforms the payload of the SOAP message using XSLT stylesheet. Depending on the differences between the two versions of the WSDL, you could transform the "old" requests to the new format with one XSLT, thus letting them be handled by the "new" endpoint. In turn, the "new" responses can be transformed to the old format again with another XSLT.

EventStore 3.0 and Publishing Events

So what would be the recommended way to publish events via Event Store 3.0? Assuming I wire up the EventStore like this:
.UsingAsynchronousDispatchScheduler()
.DispatchTo(new DelegateMessageDispatcher(DispatchCommit))
where 'DispatchCommit' looks like this:
DispatchCommit(Commit commit)
I can watch the committed events fire off as expected. However, ES 2.0 had the IContainer passing into the message dispatcher and I could resolve a bus instance and send events. Shall I use a class that implements IDispatchCommits ?
Anyone using ES 3.0 with any thoughts?
Here's the code I'm using in production to dispatch commits: https://gist.github.com/1311195
I have my container configured to only create a single instance of the dependency.

GWT eventbus handle multiple modules

I am working on a gwt project and we are using eventbus for communicating events between widgets. I have 2 modules and when i raise an event in one module, the other module is unable to receive it. How can i solve this.Any help??
Are you sure you've passed the same EventBus to both modules, and that both modules have subscribed to the event that you're publishing?
What EventBus class are you using, anyway? One you wrote yourself, or one that's included in a GWT library?
You are most likely using two different instances of EventBus in each of the modules.
Two possible reasons:
You have created two different instances (check the code for the occurrences of something like new HandlerManager(null) if you are using the supplied one, or similar).
You have a problem with passing the eventBus reference between modules; how are you passing data across these two modules?

Resources