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.
Related
I'm using the Gmail RESTful API directly (not from some library).
Looking at the documentation here Gmail Documentation.
I have managed to get the content of the message body, however it also returns the whole history chain for the current message.
Is there a way to get a response from the API only the requested message body, without the whole thread history?
According to this thread, it is not possible because it is part of the email's body content and you're specifying the ID of the message to retrieve.
You are getting the full reply message. When the report replied, they quoted the original message and this the text of the original is in the reply message. You may just want to do what Gmail and many other modern emails apps do and collapse/hide any reply text which begins with >.
References:
How to get the reply message without the original message from the Gmail API
GMAIL API : How to get the reply without the original message
Most efficient way to get new messages
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.
I'm using cucumber and citrus together, and in my #Then definition, I have the citrus HTTP response:
#CitrusResource TestRunner runner;
runner.http(builder -> {
final HttpClientResponseActionBuilder rab =
builder.client("citrusEndpointAPI").receive()
.response(HttpStatus.OK).messageType(MessageType.JSON)
.contentType(MediaType.APPLICATION_JSON_VALUE);
Is there a way to store the returned JSON message body into a java JSON object?
You can use the local message store. Each message should be saved to that local in memory storage during the test. You can access the stored messages later in that test case via its name:
receive(action -> action.endpoint("sampleEndpoint")
.name("sampleMessage")
.payload("..."));
echo("citrus:message(sampleMessage.payload())");
Please note that we named the received message sampleMessage. You can access the message store via test context in custom test actions, too.
context.getMessageStore().getMessage("sampleMessage");
Besides that you could also use a custom message validation callback in Java DSL. Here you have full access to the received message content.
receive(action -> action.endpoint("sampleEndpoint")
.validationCallback((message, context) -> {
//Do something with message content
message.getPayload(String.class);
}));
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.
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.