Ecotoneprovides abstractions for asynchronous execution.
User should be able to place order for different products.
PlaceOrderCommandwith ordered product Ids
OrderedProductvalue object, which will describe, cost and identifier of ordered product
placeOrder- Place order method make use of
QueryBusto retrieve cost of each ordered product. You could find out, that we are not using
arraytransformation, so we do not need to use
order.place Command Handlerto run asynchronously using
RabbitMQnow. Let's start by adding extension to
Ecotone, that can handle
AMQP Backed Channel(RabbitMQ Channel), in order to do it, we need to create our first
Application Context.Application Context is a non-constructor class, responsible for extending
Ecotonewith extra configurations, that will help the framework act in a specific way. In here we want to tell
AMQP Channelwith specific name. Let's create new class
ServiceContext- Tell that this method returns configuration. It can return array of objects or a single object.
order.placeCommand Handler, that it should run asynchronously using our new
channelNameused for asynchronous endpoint. Endpoints using
Asynchronousare required to have
endpointIddefined, the name can be anything as long as it's not the same as
routing key (order.place).
orders.Name comes from the message channel name. You may wonder why it is not
place_order_endpoint,it's because via single asynchronous channel we can handle multiple endpoints, if needed. This is further explained in asynchronous section.
orderIdin our testing command, so we can place new order.
bin/console ecotone:quickstartwe should get an exception:
order.placeCommand Handler to run asynchronously, so we need to run our
asynchronous endpointin order to handle
Command Message. If you did not received and exception, it's probably because
orderIdwas not changed and we already registered such order. Let's run our asynchronous endpoint
Query Handlerand check, if the order really exists now.
AddUserIdService Interceptorto perform the action before sending it to asynchronous channel. This Interceptor is registered as
Before Interceptorwhich is before execution of our Command Handler, but what we want to achieve is, to call this interceptor before message will be send to the asynchronous channel. For this there is
PresendInterceptor available. Change
Presendannotation and we are done.
Presendinterceptor, we can validate messages, before they will go asynchronous, to prevent sending incorrect messages.