Persist Correlation Id through HTTP requests - mule

In my mule flow the CorrelationId is set on the message, but after making an outbound http:request, the message loses the Correlation Id.
What is the correct way to prevent the Cid being lost?
UPDATE
No matter what I tried, the CorrelationId is always lost. I've created a JIRA issue demonstrating the difference in behaviour between http:outbound-endpoint and http:request
https://www.mulesoft.org/jira/browse/MULE-8522
I don't believe the CorrelationId is supposed to be lost in this case.

You can set the corrolation id in the message outbound so that it is available in external flow.
You can also look into the example to add Corrolation id in your message before sending to a outbound endpoint :- http://blogs.mulesoft.org/total-traceability/
UPDATE
Then use message enricher which wrapp the HTTP request component and by that way you can get the value from the external service without disturbing your actual payload and existing corrolation id
http://www.mulesoft.org/documentation/display/current/Message+Enricher

Related

Clarification on WSO2 ESB in-sequence and main sequence

I understand ESB has in-sequence, out sequence and fault sequence, Is in-sequence same as main sequence ?
Also I would like to know if we define receive sequence in a endpoint will it override default behaviour and response is handled by specified received sequence ? Will response handled by default sequence if received sequence is not specified explicitly ?
Most of the WSO2 ESB examples in internet are based on proxy service, I would like to understand how sequence can be used without proxy service, Can you please introduce me to a such tutorial ?
Triggering Messages
Messages come into the ESB through the following triggers:
A proxy service receives messages that have been sent to a specific endpoint.
A task injects a message into the ESB at a scheduled interval.
A REST API call sends a message to the ESB.
When the ESB receives a message, it sends it either to a proxy service or to the Main sequence for handling. The proxy or sequence is configured with message mediation, which controls how the message will be transformed, filtered, forwarded, etc.
To trigger messages in the ESB, see the following topics:
Creating APIs
Working with Proxy Services
Working with Tasks
Using REST
Source = https://docs.wso2.com/display/ESB481/Triggering+Messages
About the Main and Fault Sequences
A mediation configuration holds two special sequences named main and fault. All messages that are not destined for Proxy Services are sent through the main sequence. By default, the main sequence simply sends a message without mediation, so to add message mediation, you add mediators and/or named sequences in the main sequence.
By default, the fault sequence will log the message, the payload, and any error/exception encountered, and the drop mediator stops further processing. You should configure the fault sequence with the correct error handling instead of simply dropping messages. For more information, see Error Handling.
Source = https://docs.wso2.com/display/ESB481/Mediation+Sequences#MediationSequences-mainSequence
Also I would like to know if we define receive sequence in a endpoint will it override default behaviour and response is handled by specified received sequence ? Will response handled by default sequence if received sequence is not specified explicitly ?
Correct , in a proxy though , and the default behaviour is to send to "out sequence"
I am also a beginner at this , just know what I know through (a lot of) trial and error ;)
Ok so assuming you have a default offset of 0 , you're ESB instance should have 2 default transports/ports :
HTTP = 8280
HTTPS = 8243
So , any message sent to these ports will reach the main sequence , UNLESS , they are service specific endpoints, so for example , for a soap message with endpoint :
http://localhost:8280
this will reach the default main sequence , and the following
https://localhost:8243/services/yourProxyService ,
will got to the in sequence of the yourProxyService.
Also , in [esb_home]/repository/conf/log4j.properties , set/uncomment the following lines :
log4j.logger.httpclient.wire.header=DEBUG
log4j.logger.httpclient.wire.content=DEBUG
log4j.category.org.apache.synapse=DEBUG ,
this should show you much more info in the log and make it easier to know which sequence you are in..
feel free to ask me other stuff , cool

Mule:Setting Rest Call response as property in original message payload

Having a scenario where consuming a message from amqp:inboundendpoint and then requesting a call to rest service using HTTP outbound endpoint with request response message exchange pattern. I need to set properties of message payload received from amqp with certain data retrieved in HTTP outbound response. What is the best component to acheive this design. Do i need to call HTTP outbound inside an enricher and then enrich the payload with additional properties retrieved from rest call or is there any other design possible.
The message enritcher was designed exactly for this scenario please take a look a this.
Yes as Victor said, Mule Message Enricher will be a good option to be used in this kind of scenario..
What message enricher actually does is it enrich an incoming message with additional information (That's what your need ) and perform a particular task without disturbing or modifying the original payload...
So in that case, the message processor after enricher will be getting the original payload without being modified... So I can say, your approach is correct and you can go with enricher..
you can find more about enricher :- http://www.mulesoft.org/documentation/display/current/Message+Enricher
and
http://blogs.mulesoft.org/enrich-your-experience-orchestration-and-data-enrichment-with-mule-3-1/

what exactly a inbound end point and outbound end point in mule?

I have been trying to figure out, what exactly a inbound end point and outbound end point. For me it is bit of an eluding to understand.
what are exactly inbound and outbound endpoints for/do in mule flow? if a flow wants send message which endpoint shoud be used viz when receiving. Or when an application want to invoke a flow which end point it should communicate to?
Inbound endpoints are message sources (http://www.mulesoft.org/documentation/display/current/Message+Sources), which as the name suggests is where messages are created. They can be created based on external events (like an incoming HTTP request or JMS message) or by polling (like files in a directory).
Outbound endpoints and anything else you see in a flow (except exception strategies) are message processors (http://www.mulesoft.org/documentation/display/current/Message+Processors), which means they do something with the message in-flight the flow. Outbound endpoints are message processors that send the current message to "destinations" like a JMS queue, an HTTP server, a file, ...
Disclaimer: This is a simplified view to give you a general idea, its not the beginning or end of what you can do with mule (or other service buses)
Mule is a message processing engine. You can think of it as a giant conveyer belt. You put something on one end, and it goes along the belt and comes out the other end.
The thing that mule deals with are called messages.
The starting point is the "inbound end point" and the exit point is the "outbound end point"; between these pairs of end points you can have other things that will process the message as it travels from the start to the end.
A combination of a start end point + gubbins in the middle to do some work on the message + outbound end point is called a flow. You can chain flows together to create a workflow or process.
These processes are then packaged as an application and uploaded to the mule server. The process only runs when a message that it is listening for arrives. Otherwise the processes are sitting idle. Think of it like a car assembly line. The assembly line that fixes the seats in the car can only start when the chassis is finished; otherwise there is nothing for it to do. Once the seats are fixed, only then can the paint assembly line start, and so on.
Inbound Endpoint: To get the data in mule app from outside.
Outbound Endpoint: To pass the data from the mule app to the outside.
There are two types of connectors available based on operation.
Inbound Endpoint based connector : Inbound endpoint based connectors are the connectors which is placed inside a message
source area of a mule flow which is used to start executing or
triggering off the flow upon receiving the request. (or which is
used to receive the incoming request and pass the request to the
next message processors in a flow for further processing)
Outbound Endpoint or Process based connector: Outbound Endpoint based connectors are placed anywhere within a message processor
area of a flow at beginning or in the middle or at the end.
Regards,
Rajnish
Giving below the structure definition of Mule Message Object has Message Inbound Property Outbound Property Payload Variable Flow Variable Session Variable Attachment Exception Payload
When a connector of a flow (listening on a port) receives the payload its called Inbound endpoint. When in a flow we have a connectore placed in the middle and send a payload its called Oubound endpoint. Here the all the outbound properties sent to the Http Outbound flow become Inbound Properties within that flow.
For detailed explanation see the link below.
https://docs.mulesoft.com/mule-user-guide/v/3.8/mule-message-structure.

correlationId and temporary queues in RPC model - AMQP

I was reading RPC-Model in AMQP with RabbitMQ. The tutorial creates a temporary queue and also correlationId. Temporary queues are unique, so why should we need correlationId? I'm a JMS guy, in JMS we do request/response in two ways:
create temporary queue for each request/response
create one response queue and use correlationId and message selector.
can someone explain why do we need both temporary queue and correlationId in AMQP RPC model? It seems AMQP does not have something like message selector. Am I right?
Correct, temporary queues are unique to the client making the RPC request. We could create the RPC client to have a unique queue for each unique request it makes, but that would be inefficient - see the first paragraph of CorrelationId here:
In the method presented above we suggest creating a callback queue for every RPC request. That's pretty inefficient, but fortunately there is a better way - let's create a single callback queue per client.
So a better way is to have one queue which the RPC client gets response back on and uses the correlationId to match the request that the RPC client makes to the result that the RPC server sends back.
...having received a response in that queue it's not clear to which request the response belongs. That's when the correlation_id property is used. We're going to set it to a unique value for every request. Later, when we receive a message in the callback queue we'll look at this property, and based on that we'll be able to match a response with a request. If we see an unknown correlation_id value, we may safely discard the message - it doesn't belong to our requests.
So referencing the Summary section of the RPC tutorial:
when a client starts it creates an exclusive and unique queue
when it sends an RPC request it sets the reply_to which is the queue name (so the server knows which queue to send a response to) and also sets a correlationId which is a unique val for each RPC request
the request is sent to the RPC queue
the RPC worker (or server) receives the request processes it then using the reply_to value sends the response back to the client, it also sets the correlationId
the RPC client waits for a response and when it receives one uses the correlationId to MATCH the response with the request

Mule Dynamic flow name runtime

I was wondering whether anyone had any experience dynamically setting the name of the flow I want to redirect to in Mule? The use case is that I might have data coming in and I want to route the request to a specific flow based on the data coming in. However, the mule-config may not know of this flow until runtime, so I need to select a flow that corresponds to the data in a certain incoming field.
Many thanks.
Selecting a destination flow is usually done by sending a message to the inbound endpoint of the desired flow.
For example, if you use VM inbound endpoints in your different flows, you can then at runtime use a dynamic VM outbound endpoint that will target the right VM inbound endpoint.