Asynchrony
Asynchronous Processing in Synchronous Requests
When a client sends an HTTP batch request or a callback request, the server actually processes the data asynchronously using the Symfony Process mechanism.
Batch Requests
Batch requests allow combining multiple requests into one, reducing network and server load. The server receives a single request containing multiple operations, processes them asynchronously, and returns a single response with the results of all operations.
Callback Requests
Callback requests use the $rpc.callback parameter, which contains a DSN for the callback. The server accepts the request, validates the DSN, immediately returns a confirmation response, processes the request asynchronously, and sends the result to the specified callback URL.
Using Asynchronous Transport for RPC
The second option involves configuring the parameter async:rpc_async, which accepts a DSN for connecting to asynchronous transport such as RabbitMQ, Redis, Kafka, etc. In this case, the RPC server uses the Symfony Messenger.
Connecting Asynchronous Transport
To start the consumer, you need to run the command:
This will start the RPC server as a listener for the specified transport, and it will process all RPC requests that come through this channel.
Advantages of Using Asynchronous Transport
- Scalability: Using asynchronous transport allows easy system scaling by adding new consumers.
2. High Performance: Asynchronous transport ensures fast processing of a large number of requests by distributing the load among different system components.
3. Reliability: Using transport systems like RabbitMQ or Kafka guarantees reliable message delivery and request processing.
By utilizing these asynchronous capabilities, you can significantly improve your system's performance and provide a more convenient and faster data exchange between the client and the server.