Reactor RabbitMQ in your Reactive Spring Boot Application — Part 2

preview_player
Показать описание
-------------------

In this part 2, I'm working on Sender Service.

I have implemented on RabbitMQ & Router configuration for the sender.

In Router Configuration, I have used Router function to use Spring Webflux to its full potential I believe it is better to move away from the controller annotation-based and move towards using functions to route and handle requests.
I have defined the end-point of the Sender Service.
This class has to be annotated with @Configuration. Inside this class, we will create a bean called routerFunction that will route the incoming requests to the handler. It works just like the controller that you may be used to.

I have created class for product & product order model, product dto class.
The product order model, is made of a collection of products and also has a total cost associated with it. Because this total cost is calculated when the object is created it makes sense to create a Product DTO with a flat structure that will be used to transport the data from the client to the server and will only calculate the total value after the object has been validated.

I have created product service in order to create sender method, in order to send message queue.
I have named the queue message in RabbitMQ Broker as "spring-reactive-queue"

I have created product handler service to receive POST request from the router.
The purpose of this handler is to take the server request coming from the router functions so that we can extract any information that the request may have, call our service for the business logic and eventually return a server response for the client.
I have created a private mapperProductDTOtoEntity in this product service in order to use an ObjectMapper to map the product order instance as a JSON string and then serialize the JSON string to bytes.

With the product order serialized we can create the outbound message and then finally push the message to the queue.

I have created senderOrder method is to extract the JSON object from the server request. With the DTO extracted we can send it to the service and then finally return the server response with a 201 status and the mono order inside the body.
#khmerside
-------------------
Track: QR - XXI [NCS Release]
Music provided by NoCopyrightSounds.
-------------------
Hope this video can bring you with new idea and happy day...
Help to subscribe, like and command to support my work.
Рекомендации по теме
Комментарии
Автор

Thanks for the video. I have one question though. Shouldn't the bean returning the Connection supposed to be scheduled in a different thread pool?

harshaghanta
visit shbcf.ru