Download the PHP package serrvius/amqp-rpc-extender without Composer
On this page you can find all versions of the php package serrvius/amqp-rpc-extender. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package amqp-rpc-extender
About
The extension of symfony/amqp-messenger that allow to implement CQRS/gRPC (call and wait response) in RabbitMQ Broker, idea has to used it in microservices architecture
What it does
This bundle use ampq://
default transporter of symfony. The CompilerPass of bundle connect those
layers of default amqp-messenger to control the messages that have specific stamp.
The queues type is recommended to be used direct
Requirements
Installation
Usage
We need to replace de default symfony messenger serializer messenger.transport.symfony_serializer
with the one that
provide the extension messenger.transport.rpc.symfony_serializer
, that is needed
to encode and decode the messages in the right way.
Gateway side
All call initiator messages (from the gateway) classes need to implement the interface:
the abstract method amqpRpcStamp
should return the instance of
For command messages (classic async work - don't need the callback) the method:
amqpRpcStamp
should return: Serrvius\AmqpRpcExtender\Stamp\AmqpRpcCommandStamp
For query messages (need response from microservice) the method:
amqpRpcStamp
should return: Serrvius\AmqpRpcExtender\Stamp\ Serrvius\AmqpRpcExtender\Stamp\AmqpRpcQueryStamp
Examples of gateway messages:
Query message:
Command message:
Those stamps AmqpRpcQueryStamp
and AmqpRpcCommandStamp
implement the AmqpRpcStampInterface
Microservice side
On microservice side we have two ways of handle the message, for correct decoding the message and map it into object bundle offer annotations or classic interface implementing:
The command need to implement the interface
the methods executorName
should return the name of executor of gateway command
and in method setCommandData
the bundle will put the input message as array
Examples of microservice command messages:
the second way to define the message is to use the annotation
the attribute of it is name
represent also the executorName
from gateway
in that way the data will be mapped into object to properties the handler will be implemented as usual
The query messages like command was two ways of definition, by the interface
or annotation
Examples of microservice query messages:
the method executorName
should return the executorName
from gateway query call
and in method setQueryData
will receive the input data as array.
On command the handler will be called as usual messenger doing it
The annotation version of message is:
the name
of annotation is also the executorName
of gateway message and the data
will be mapped into properties
The handler of query should return the data that to return it on the gateway request which will waiting for it
For accessing the response data from query request after message was dispatched in envelop that will be returned by dispatch, access the stamp.
The stamp has the method getResults
and there will be present the response data
also like additional stamp with response there will be the HandledStamp
Additional
The query request stamp
accept those attributes:
$routingKey
- the routing key that was defined in messenger queue$executorName
- the executor name (by default it will use the routingKey)$waitingResponseTTL
- the time (in seconds) for waiting the response from microservice, default is 10 secons$priority
- the priority value, by default it was not set The extension don't call the gateway messages handlers
Remarks
The inspiring and documentation used for did that work was taken from:
All versions of amqp-rpc-extender with dependencies
ext-amqp Version *
symfony/amqp-messenger Version ^6.4
symfony/property-info Version ^6.4
symfony/uid Version ^6.4
symfony/serializer-pack Version ^1.1