spring kafkatemplate correlation id - java

Currently I am using spring kafkatemplate to send byte message to kafka topic.
At consumer side, we deserialize this byte message to appropriate message type.
Now we have requirement where we also need to send correlationid along with the message to Kafka topic.
Can i send correlation-id along with the byte message on kafka topic and retrive it seperatly at consumer side?

The upcoming v0.11 of Kafka adds support for custom message headers. They'd be the prime candidate to put the correlation id into.
Until then, I'm afraid you have to put the correlation id into the message value. Your serializer and deserializer should encode/decode it together with your actual payload into/from a byte array.

According to Kafka Docs,
CorrelationId is a user-supplied integer. It will be passed back in the response by the server, unmodified. It is useful for matching request and response between the client and server.
If I talk about java api, then on consumer side you can get only(topic_name,partition,offset,value) related to the message.
You can send correlationId as a part of message, but you have to parse the message to get it on consumer side.

Related

Apache Camel : extract to-queue name from message body

I have a requirement where I have to send message to Microsoft Teams.
I am trying to extract "to" channel name information from message I receive from queue and based on the channel name, I read it's url from properties file and send message. Below is the code for that.
RouteDefinition from = from("jms:queue:teamsq?connectionFactory=artemis");
from.setHeader("Exchange.CONTENT_TYPE", constant("application/json"));
final StringBuffer channelName = new StringBuffer();
from.process(exchange -> {
String[] dataArray = exchange.getIn().getBody(String.class).split(",", 2);
channelName.append(dataArray[0]);
exchange.getIn().setBody("{\"text\" : \"" + dataArray[1].trim() + "\"}");
})
.log("Body is : " + channelName + " : ${body}");
When body is logged, value of channelName is null.
Any help how can I get value of channelName outside this process() method?
Message received from queue is
channel1, This is test a message 5
Thanks in advance.
You can set a message header or an Exchange property. Both are kind of message variables to use during route processing.
.setHeader("channelName", channelName.toString())
.setProperty("channelName", channelName.toString())
The main difference is that Exchange properties are sitting on the Camel Exchange while message headers are part of the message itself.
The Camel Exchange is a Camel wrapper around the message. It is created when the message enters the route and thrown away at the end of the route.
Exchange Properties:
are only available during Camel route processing
are never sent to other systems
are only in-memory
Message headers:
are converted to message headers for the target system whenever the route does a routing to another system
are therefore sent to other systems
are serialized when sent to another system
If you send a message from a Camel route to a JMS queue and consume it from another route, the Exchange properties are no more available while the message headers are still present.
However, if you route to a direct endpoint (Camel in-memory endpoint), the whole Exchange is transferred and Exchange properties are still available.

What is RFH header in MQ messages and its purpose

When I am writing message in MQ queue through JMS, RFH header is also getting added with message as its property.
Property including
Jms delivery Mode
JMS Destination
JMS Timestamp
Mcd.msd
Can anyone explain me its use and significance?
The RFH header only allow for a single header to exist in a message, and the RFH2 header allow multiples headers to exist in a message.
I'm not going to explain, this site explained it better than I can :
New Link (previous one was not working anymore)
https://docs.actian.com/dataconnect/11.4/index.html#page/User/RFH_Header_Support_3a_Websphere_MQ.htm
I hope it will help you !

Auto-Replies to an email ,from gmail don't have 'In-Reply-To' and 'References' header

When an Auto-Reply Message is generated by Gmail for a message, the auto-reply message is not Threaded like a normal reply and the auto-reply message does not contain In-Reply-To: and References: header in its Headers Payload. The ThreadID of the auto-reply is different than its original message (unlike a normal reply where ThreadID remains same)
Which logic should we use to co-relate an auto-reply to its original message? In Other words, how do we figure out to which message is an auto-reply for?
Using Gmail API
There will be a portion of the subject of the auto-reply that matches the subject of the received email. Also, the timestamp will be close but later than the timestamp of the received email. It's not perfect, but should be functional.

Mule: sending an input stream payload (from file) along with file metadata to http outbound endpoint

I have an input stream payload with data from a file. The file can be very big. I'm sending the input stream to an http/https outbound endpoint. However, I'd like to also send metadata with the contents of the file, such as the file name and possibly other key/pair values in the post request.
If I have an input stream, and also a few strings which I want to send as a single post data, what would I need to do with Mule on the payload in order to have them all sent properly?
Basically what you want is to have inbound properties available as outbound so that they are send along with the message payload.
You may copy individual property if you just care about some like
<set-property propertyName="originalFilename" value="#[message.inboundProperties.originalFilename]"/>
or you could copy all of them at once like
<copy-properties propertyName="http.*" doc:name="Copy All HTTP Headers"/>
You can do this before calling http outbound endpoint

How does a tibco ems queue send a soap response to the publisher

While using a soap/jms web service , i am using an EJB deployed on a WAS as my client. My service endpoint is a tibco ems queue. To call the service, i construct a SOAP messgae and drop it on the queue.
But my confusion is: How can the 'queue' send me back a response? I understand how http request response works, but with queue (I only have experience with traditional MQ), I don't know how queue can return a proper resposne to the publisher.
Let us say there is an MDB that consume the message from the queue, invokes the service method and then puts the response back on the queue? And then the queue sends the response back to the client?
The response will be sent back on a different queue or topic, which is specified in a property of the request message.
The response queue/topic can be set in the request message using the method msg.setJMSReplyTo(destination) (http://docs.oracle.com/cd/E17802_01/products/products/jms/javadoc-102a/javax/jms/Message.html#setJMSReplyTo%28javax.jms.Destination%29).
When using the QueueRequestor to send the request, as usual and recommended, then a temporary queue is created for each individual request-reply interaction.

Categories