Asynchronous Message Handlers
Last updated
Last updated
Ecotone does allow for easy change from synchronous to asynchronous execution of given Message Handler.
In order to run Command Handler asynchronously we need to mark it as Asynchronous.
The same way we define for Event Handlers:
We need to add endpointId on our endpoint's annotation, this will be used to route the Message in isolation to our Message Handlers.
The "orders" string is actually a name of our Message Channel. This way we reference to specific implementation which we would like to use. To provide specific implementation like for example Database Channel, we would use ServiceContext.
This is basically all we need to configure. Now database channel called orders will be used, whenever we will use Attribute with this name.
There are multiple different implementation which we can use:
At this moment following modules with pollable channels are available:
After setting up Pollable Channel we can run the endpoint:
You may set up running configuration for given consumer while running it.
handledMessageLimit
- Amount of messages to be handled before stopping consumer
executionTimeLimit
- How long consumer should run before stopping (milliseconds)
finishWhenNoMessages
- Consumers will be running as long as there will be messages to consume
memoryLimit
- How much memory can be consumed by before stopping consumer (Megabytes)
stopOnFailure
- Stop consumer in case of exception
Dynamic configuration overrides static
Using single asynchronous channel we may register multiple endpoints. This allow for registering single asynchronous channel for whole Aggregate or group of related Command/Event Handlers.
You may put Asynchronous
on the class, level so all the endpoints within a class will becomes asynchronous.
Each Asynchronous Message Handler requires us to define "endpointId". It's unique identifier of your Message Handler.
Endpoint Id goes in form of Headers to your Message Queue. After Message is consumed from the Queue, Message will be directed to your Message Handler having given endpoint Id. This decouples the Message completely from the Message Handler Class and Method and Command/Event Class.
EndpointId ensures we can freely refactor our code and it will be backward compatible with Messages in the Queues. This means we can move the method and class to different namespaces, change the Command class names and as long as endpointId is kept the same Message will be delivered correctly.
If you're choose Ecotone
will use to atomically store your changes and published messages.
Currently available Message Channels are integrated via great library .
Using configuration for statically configuration.
All asynchronous endpoints are marked with special attributeEcotone\Messaging\Attribute\AsynchronousRunningEndpoint
If you want to all polling endpoints you should make use of on this.