I have a http inbound gateway which needs to receive the request validate it and then immediately send response to client. After the response is sent back, my SI flow needs to continue with further processing. The response should be sent to client as soon as the validation is complete. Sending of response shouldn't wait until my entire processing is complete. How can I trigger SI flow to continue with further processing once the response is sent. What is the appropriate SI component for this scenario?
If the response is a simply 200 OK, use an inbound channel adapter (not a gateway) and make the first channel after the validation an ExecutorChannel. Then, immediately the message is handed off to the executor, the response will be sent.
If you need a custom reply, use a gateway and make the first channel after the validation a publish-subscribe channel (with an executor), construct the reply in one consumer of that channel, process the request in another.
Related
I have a doubt, in a group chat system that has a database with a rest API, who should issue the event of a new message?
The client or the endpoint to create the new message?
For example: X user sends a message to group Y, then uses the api endpoint api.com/message-create and that endpoint emits the message-create event through websocket
Example 2: X user sends a message to group Y, then uses the api api.com/message-create endpoint and the endpoint does not emit the message-create event, but was emitted when the user pressed the send message button
I still don't quite understand if it would occupy more websocket channels to achieve that, if a global one is enough, etc.
The server should be responsible for communication logic. So your first example is better.
But: why do you use two communication channels for sending an creating messages?
If you use websocket, you don't need create a message from a client by using additional rest endpoint.
This approach is prone to errors. For example if the client will loose network connection after sending message through websocket and before executing call to the REST endpoint?
The message will not be stored in a database.
Your flow should looks as follows:
User clicks the send button.
Message is send through the websocket.
Message is stored in the database asynchronously (you can do it directly from communication server, or use rest endpoint)
Emit "new message" event to the group.
I have the following scenario, where i can not respond directly to the request of a MassTransit RequestClient
Request Service 1 implementing a RequestClient and calling GetResponse
Another service 2 have the consumer of the request that just save the request information (messageId, requestId ...) to some storage and not send a response back.
Based on an API call in service 2, we can find the saved request information and send back the response to the RequestClient. I could achive this by sending the response to the temporaty queue of the RequestClient bus but the message ends up in the skipped queue of the temporary queue and GetResponse never gets the message.
How can i make the message arrives to the main temporary queue, and that the GetResponse consumer find it.
If anyone has a similar scenario. We achived this by implementing an event waiter mechanism in the consumer. When the external API call is made in service 2, an internal event is fired then consumer who is waiting for it through ResetEvent continue by gathering the response and send it back through out of the box RespondAsync.
I want to create long polling client for a web service using RxJS.
Targeted endpoint that supports blocking requests sends x-index header to a client with a value representing current state of the endpoint. This x-index value is being sent in subsequent requests as a query parameter so the endpoint responds only when x-index changes or when request timeouts.
--> client sends first request to the server
<-- server immediately responds with a x-index header
--> client sends blocking request with a value of x-index as a paramter
<-- request is suspended until change of the state or until timeout, then server sends the response
if x-index is changed then pass data to subscriber && repeat from step 3.
I don't know how to create that loop of server requests with changing x-index parameter. Anybody can help, please?
I would like to implement an request/response pattern in the following parts:
Server: Springboot with ActiveMQ
Client: JavaScript with stompjs over websocket
I want a behaviour like an http request.
Send a Request, get a corresponding Response.
I try to do this with temporary channels
I send 3 Messages
The steps are:
SUBSCRIBE to a temprorary channel
SUBSCRIBE
id:mysub
destination:/temp-queue/example
SEND the request and include a reply-to header with the subscribed channel of Step 1
destination:/queue/PO.REQUEST
reply-to:/temp-queue/example
Get the Response Message from the Server
MESSAGE
subscription:foo
reply-to:/queue/temp.default.23.example
destination:/queue/PO.REQUEST
reply-to:/temp-queue/example
But now (As Client send messages asynchronous) im not sure if Step 1 is complete on server, and so server is ready to send Response to the queue when the Request of Step 2 arrives at the server.
Is it possible that server finishes Step 2 before finishing Step 1, and so sends the response to nowhere? Or does ActiveMQ ensures that the received messages 1 and 2 from the client are processed and finished in the correct order?
Can any race condition between message 1 and 2 happen?
Thank you very much!
Any STOMP frame that your client sends can be sent with a receipt request that makes the processing of that frame synchronous. So if you want to ensure that a subscribe is complete before doing the send, then attach a receipt-id to the subscribe frame and wait for the spec mandated RECEIPT frame before going on to do the send, this ensures that your subscription is setup prior to any other processing.
I need to callback request after output of otbound gateway . My components :
Input Message -> Service Activator ->webservice OutBound Gateway -> Response Message
here I need to check response message and supply new message as input message which depends upon response code.
Your question is not clear; you should show the configuration you have tried.
You can simply add a reply channel to the gateway and add more processing after that channel.