Skip to content
Advertisement

Http request and response from rabbitmq

I have question about http request and rabbit mq . How I can have this sample 1- client request to server with http request

2- severe after receive request put to rabbit mq

3- in one job , lisiner read message after process on time response to client with http response

Is it possible ? If yes please help me

Advertisement

Answer

it’s possible to save your httpRequest in rabbitMq and it’s possible to read them in a job from rabbit. but it’s not possible to send back HttpResponse to a request which you have red from rabbit !!!!

it’s because of : http basically is an online protocol which means that client wait until you respond back to client and if you don’t send back the response online it will get an error.

but let me help you with what are you looking for :

what you are looking for is an event base system . in such a system everything is status base. in an event base system you get the request from client . then you persist the request somewhere with requested status and respond back to client and tell him your request persisted successfully ( but not processed ).

then in a job or other ways you fetch requests with requested status , then start to process them. after processing them , you persist them again somewhere with processed status or ErrorWhileProcessing status . then clients can send request to observe the status of their requests.

for example the client ask for transferring some money . then you just persist the request somewhere with requested status and respond back to client that your transfer request is persisted successfully ( but not processed yet ). after a while , by using a job or a listener on your rabbit , you fetch the requested transfers (transfers with requested status ) and start to process them. after processing if the transfer where successfully done , persist that again with successfully processed status and if encounter some error , persist it with error status ( with reason ) . then whenever client want, can send request to observe the status of his transfer request.

Advertisement