Camel - Receive reply from ReplyTo using either Producer/Consumer Template - apache-camel

Our app (say abc) need to interact with another app (say xyz) using Tibco queues.
The xyz will listen to incoming messages in Queue1.
Then it would send back the response message Temp queue, we have populated in the request message header.
From abc, we are sending the messages to Queue1 using ProducerTemplate.
We have set the JMSReplyTo in the headers.
Now we want to receive the message which would be sent to the Temp Queue.
Along with the body, we also need the headers which xyz would be populating and sending us.
Is this possible using Producer/Consumer Template? If yes, can you highlight that pls.
If not, what is alternative?

Related

Apache Camel: What meaning of "attachments" in message model?

I read the book Camel in Action. But I can't understand what attachment mean in its message model.
I know headers such like sender information, receiver information, or data encoding etc. However, I don't know what is mean of attachments?
Lets run through some examples
You are consuming a file, camel can create a message with contents of the file as payload and file name etc as message headers
You are consuming a jms message, camel can create a message with contents of jms message as payload and jms header etc as message headers.
You are sending simple http request, camel can crate a message with what is inside the http request as paylaod and url etc as headers
Then you have some other components
You can send an email with some text in the body and some attachments, so in this case camel creates a message with payload, headers and attachments
You can also send SOAP request with attachments, in this case also, camel creates the message with payload, headers and attachments.
But there is not many camel components which support attachment. There is few like email, soap service etc

Put/Post JSON message to Azure Storage Queue via Logic App

I want to be able to use Logic Apps to put/post messages in an Azure Storage Queue, because I want to make use of the Managed Identity option that HTTP Logic App acion provides.
I have a Logic App that uses HTTP action to post XML messages to the queue and I have a "Put a message on a queue" action that puts JSON message to the queue for debugging purposes.
My ultimate goal is to be able to use the HTTP action with Managed Identity as Authentication but be able to post JSON messages to the queue like the "Put a message on a queue" action is able to.
You can certainly send JSON as message body. In fact you can send any text. You just have to ensure that the text you're sending as message body must be XML safe e.g. replace < with < etc. Generally Base64 encoded string messages are sent to ensure this.
From the REST API documentation:
A message must be in a format that can be included in an XML request
with UTF-8 encoding. To include markup in the message, the contents of
the message must either be XML-escaped or Base64-encode. Any XML
markup in the message that is not escaped or encoded will be removed
before the message is added to the queue.
Here is what worked for me:
Enabled "Managed Identity" on the Logic App.
Added Storage-Queue-Contributor permissions on the storage queue.
Used utcnow('R') to get this date format ("Tue, 08 Sep 2020 12:03:08 GMT")
for x-ms-date HTTP header (no doc from MS about this).
Inserted JSON data inside
<QueueMessage>
<MessageText>
{
"car": "Audi",
"year": 1983
}
</MessageText>
</QueueMessage>
Final result in Logic App designer:

Asynchronous request-response across two Netty channels in Camel

I have to integrate with a legacy host that uses TCP/IP communication with separate request and response channels. You send a request to the host on one channel where it is the server, and you need to have a server channel open on which it will send the response some time later. The communication is asynchronous, so there is no guarantee that the next message you receive will be the response to the request you just sent - you have to use a correlation key in the response to tie it back to the request.
I have a Camel route that takes the incoming request and sends it out to the host, and another route that listens for the responses. I have a third route that uses an aggregator to tie the response back to the request using a correlation key. Roughly speaking, the routes look like this:
from("direct:myService")
.process(exchange -> exchange.setProperty("CorrelationKey", exchange.getIn().getBody(MyMessage.class).getCorrelationKey())
.to("netty4:tcp://somehost:555")
.to("direct:aggregate");
from("netty4:tcp://localhost:555")
.process(exchange -> exchange.setProperty("CorrelationKey", exchange.getIn().getBody(MyResponse.class).getCorrelationKey())
.to("direct:aggregate");
from("direct:aggregate")
.aggregate(header("CorrelationKey"), (oldEx, newEx) -> {
if (oldEx == null) {
return newEx;
}
oldEx.getOut().setBody(newEx.getIn().getBody());
oldEx.setProperty(Exchange.AGGREGATION_COMPLETE_CURRENT_GROUP, true)
return oldEx;
}).completionTimeout(5000)
.process(exchange -> logger.log("Received response"));
The aggregation strategy works in the sense that I only see the log message once the response has been processed. The problem is that the request route ("direct:myService") doesn't wait for the aggregation - it has already returned back to the caller. What I want is for that route to block until the aggregation strategy has got the response, so that the message received by the netty4 consumer is used as the out message of the direct:myService route. Is that possible?

Mule Request Reply: Send Reply After All the Flow Processed

currently I am working with mule. I have 3 flow: RequestFlow, ServiceResponse, and SendResponse.
On the first flow, I processed the request (transform the request parameter, write it into wmq, etc). FYI, wmq on this flow can only be used for write.
On the second flow, I read the response from server via another wmq, transform it into json, and send to VM. FYI, wmq on this flow only can be used for read.
On the third flow, I tried to send back the response to the first flow and generate a file.
To send back the response from flow 3 to flow 1, I try to use request-reply
But, unfortunately, when I tried to send a request, I found out that:
After it reach request-reply component on the first flow, it will directly go to the third flow.
And then, after mule processed all the operation on the third flow, it will send the response back to the request-reply component.
Do some logging (logger component on first flow)
Then, go to the flow, processed all the operation
Processed the third flow again
That's why, after all the process has been finished, my application will:
Generate 2 files (1 contain request xml and 1 contain json response)
Return the request xml to http
However, It's not what I want. The flow that I need is:
Mule processed the operation on first flow until the request-reply component
Go to the second flow and processed all the component
After it finish with second flow, it will goes to third flow. Proceed all the component
Send the reply back to request-reply component on the first flow
Do some logging (logger component in first flow)
And finish
Result from this application should be:
1 File contain JSON response
JSON Response on http
So, how to do so? Thanks in advance.
You don't show the flow that consumes the messages sent to the sender path by the VM outbound endpoint in request-reply: I'm assuming it's a flow that takes care of sending the message to the server.
It seems that all you miss is an VM outbound endpoint in SendResponse that would send the message to the response path, onto which the VM inbound is waiting in the request-reply.
PS. Of course, it's assumed the the server propagates the JMS correlation ID from the request message to the response message, otherwise Mule (nor any client for that matter) could ever reconnect the response to the request and the request-reply would fail.
PPS. You don't need an all router around the single VM outbound endpoint in request-reply.

Convert email to http request with App Engine

Is there a way to send http request (to a specific url address) each time i receive email (Google account), with the content of the email received using Google App Engine?
As per your question, it seems that you already have an Incoming Email Handler in your App Engine application.
If the above is true, then in the Incoming Email Handler, you can parse out the message and if it meets your condition for invoking the http request, then you can definitely do that. You can use the URL Fetch service for the same.
One design decision you might want to do is whether you want to keep all your URL Fetch code inside of the incoming Email Handler or you want that to be handled externally via a Task Queue. In that case, I suggest that you can use the Task Queue to create a task when an incoming email comes in to your handler. Then the Task Queue logic can take care of one or more things, which includes invoking the HTTP Service, as you wanted.

Resources