Messaging Gateway
Message Gateway PHP
Last updated
Was this helpful?
Message Gateway PHP
Last updated
Was this helpful?
The Messaging Gateway encapsulates messaging-specific code (The code required to send or receive a ) and separates it from the rest of the application code.
It takes Application specific data and convert it which then is sent via This hide Messaging specific code, from user's code.
Ecotone aims for eliminating Framework related code from Business related code, that's why Gateway can defined as interface in user's code base. Ecotone is responsible for generating implementation for any interface.
To implement custom Gateway, we will be using clear interfaces and message channel.
By default gateway will be available under interface name in DI, in that case Product\ProductGateway.
If you want to register it under different name for example "productGateway", then pass it to annotation #[ClassReference("productGateway")]
If you are using Symfony Integration, then it will be auto registered in Dependency Container with possibility to auto-wire the gateway.
2. Gateway
enables method to be used as Messaging Gateway. You may have multiple Gateways defined within interface. The "buyProduct"
is a channel name that we will be requesting.
In some cases you may want to invoke Query/Command Handler directly, not via Bus. In that case you may define Message Gateway that routes to given Handler.
Service Command Handler:
Gateway:
This also works for Query Handlers. This way we can build an interface, which provides API for given set of behaviours e.g. OrderApi
.
You may expose Aggregate's Command and Query Handlers through interface.
Aggregate:
Gateway:
Repository implemented via interfaces are just higher level abstraction of Message Gateway. You enable them by marking attribute #[Repository].
Parameter converter types:
This will convert string passed under $content
parameter to message payload
This convert $content
to message's payload and will add to headers under "receiverEmail" key value of $toEmail
Using combination of Messaging Gateway and we can build our own Buses. Messaging Gateway will be responsible for building Message and sending to the Router. And Router will be then based on need route it by payload / headers or whatever is needed.
Gateway may return values, but as you probably remember, everything is connected via . So how does we get the reply?
During building, gateway adds header replyChannel
which contains automatically created Channel. During , if any value was returned it will be sent via reply Channel.
This way gateway may receive the reply and return it.
If you have registered for specific Media Type, then you can tell Ecotone
to convert result of any to specific format. This is especially useful, when we are dealing with QueryBus
, when we want to return the result to the caller of the request.
In order to do this, we need to make use of Metadata
and replyContentType
header.
Read more about Repositories in .
In order to build , Parameter Converters are introduced. You may configure them manually or let Ecotone make use of default parameter converters.