Callback in Outbound Gateway Spring Integration - spring

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.

Related

In a group chat, should the new message event (websocket) be sent by the client or the API?

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.

Send messages to the temporary queue with MassTransit

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.

Is it guaranteed that subscription for response is established before request is processed in temp-topic based request/response scheme?

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.

Spring Integration: Send response to client http inbound gateway

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.

WSO2 ESB task (scheduler) doesn't work

I have to send XML message to my jms proxy service (service receive and send back message over JMS) with ESB Task (scheduler).
I tried 2 solutions.
1 solution
In added task I fill:
message -> my XML
injectTo -> set 'proxy'
proxyName -> my proxy name
The result is that, my jms proxy receive the message but without JMS_Corelation (I guess the message is send local in ESB) and I get that error:
Unexpected error sending message back
org.apache.axis2.AxisFault: Transport out has not been set
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:432)
at org.apache.synapse.core.axis2.Axis2Sender.sendBack(Axis2Sender.java:163)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:321)
at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:94)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:255)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.mediateFromContinuationStateStack(Axis2SynapseEnvironment.java:556)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:198)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:488)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:170)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.axis2.transport.local.LocalResponder.handleResponse(LocalResponder.java:214)
at org.apache.axis2.transport.local.LocalResponder.invoke(LocalResponder.java:111)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.synapse.core.axis2.Axis2Sender.sendBack(Axis2Sender.java:163)
at org.apache.synapse.mediators.builtin.RespondMediator.mediate(RespondMediator.java:23)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:255)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.mediateFromContinuationStateStack(Axis2SynapseEnvironment.java:556)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:198)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:488)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:170)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
If I send this message to queue, all workflow works fine, so it is well configure.
2 solution
In added task I fill:
message -> my XML
to -> my jms endpoint
format -> message format
The result is that, there is no result becasue nothing is happend. My jms proxy service doesn't receive any message.
Someone knows how to fix that?
Maybe there is another way to do that?
Your JMS Proxy is configured to receive messages from a JMS queue or topic.
You should try to write a named sequence that send an appropriate message into your queue or topic. Then, configure your scheduled task to call this sequence :
injectTo = sequence
format = soap11 (for exemple)
soapAction = mySoapAction (if needed)
message = <root>myMessage</root>
sequenceName = YourSequenceThatSendTheMessageToJMS

Resources