Mule 3 async-reply - mule

I have a flow where I receive request via webservice. I forward that request to a JMS queue using component binding. However, I would like to get async-reply from that queue and use it as response to the webservice. Do I need to use reply-to and async-reply-router in the flow? Or is there any other way to do that in Mule 3? Any pointers?
<flow name="mviService">
<http:inbound-endpoint address="http://localhost:62005/mvi"
exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="com.xyz.services.mvi.MVIServicePortType" />
</http:inbound-endpoint>
<component class="com.pennmutual.services.mvi.MVIServiceImpl">
<binding interface="com.pennmutual.mvi.helper.XMLReqProcessorInterface"
method="process121Order">
<jms:outbound-endpoint queue="mviq.121.order" />
</binding>
</component>
<async-reply>
</async-reply>
</flow>
============ EDITED - SEE BELOW FOR RE-FRAMED QUESTION =================
I think I haven't done a good job in describing the scenario. Let me try again. Here's the scenario --
A client calls our service described in this flow "mviService". mviService gets XML request via HTTP/SOAP based inbound endpoint. Let's call this request as XML121Request.4
A component defined in MVI "com.xyz.services.mvi.MVIServiceImpl" makes some changes in XML121Request.
Forwards this XML121 to a JMS queue "mviq.121.order". It uses component binding for this.
The outbound endpoint to this JMS queue is a third party web service where this request is forwarded. The third party acknowledges the receipt of XML121 and the synchronous web service call returns.
The response from that third party service comes at a later point of time, which is generally couple of seconds. The response comes asynchronously. Third party invokes another webservice endpoint on MVI and sends the XML121Response.
MVI puts this response in a JMS queue named "mviq.async.service.reply".
The "mviService" flow needs to wait for this response and send this response (after some modification) to caller(in step 1).
I'm able to get the response from third party and this response is enqued in a queue named "mviq.async.service.reply". I would like to use/consume this message and return it as a response to first call to MVI.
I'm trying to use "request-reply".
<request-reply timeout="60000">
<vm:outbound-endpoint path="request" />
<jms:inbound-endpoint queue="mviq.async.service.reply"
exchange-pattern="one-way" />
</request-reply>
THe problem is that even though I don't want to have outbound-endpoint in this case, I still have to put one as this is required by request-reply tag. The flow waits for 60 seconds at that point of time but even if I put something in the queue "mviq.async.service.reply" the correlation ID doesn't match so the service timesout and returns an error.
flow is mentioned below.
<flow name="mviService">
<http:inbound-endpoint address="http://localhost:62005/mvi"
exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="com.xyz.services.mvi.MVIServicePortType" />
</http:inbound-endpoint>
<component class="com.pennmutual.services.mvi.MVIServiceImpl">
<binding interface="com.xyz.mvi.helper.XMLReqProcessorInterface"
method="process121Order">
<jms:outbound-endpoint queue="mviq.121.order" />
</binding>
</component>
<!-- <logger message="XML Correlation ID 1 is #[mule:message.headers(all)]" /> -->
<request-reply timeout="60000">
<vm:outbound-endpoint path="request" /> <!-- we don't care about this -->
<jms:inbound-endpoint queue="mviq.async.service.reply"
exchange-pattern="one-way" />
</request-reply>
<!-- <component class="com.xyz.mvi.CreateMVIServiceResponse"/> -->
</flow>
===== FLow with REPLY TO =============
<flow name="mviService">
<http:inbound-endpoint address="http://localhost:62005/mvi"
exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="com.xyz.services.mvi.MVIServicePortType" />
</http:inbound-endpoint>
<component class="com.xyz.services.mvi.MVIServiceImpl">
<binding interface="com.xyz.mvi.helper.XMLReqProcessorInterface"
method="process121Order">
<jms:outbound-endpoint queue="mviq.121.order" exchange-pattern="request-response">
<message-properties-transformer scope="outbound">
<add-message-property key="MULE_REPLYTO" value="mviq.async.service.reply" />
</message-properties-transformer>
</jms:outbound-endpoint>
</binding>
</component>
</flow>

I'd like to suggest you do not create a service component class and instead use cxf:proxy-service, which will give you direct access to the SOAP envelope and the opportunity to assemble the response the way you want at XML level.
This will free you from the constraint a service component class imposes on you, hence waive the need to use bindings and open the door to using request-response.
See this SO answer and check the (skinny) proxy service user guide for more information.

Related

Mule JMS Topic and ActiveMQ Configuration

I am using Mule ESB to design a process whereby one can post a message to a topic. Subscribers will listen to the topic and receive messages. Each subscriber will act on the messages differently. The goal here is to have the ability to post a test message to the topic from HTTP for testing subscribers.
Here is how I have the JMS connection configured:
<!-- JMS Topic connector -->
<jms:activemq-connector name="jmsTopicConnection" specification="1.1" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ2" durable="true" numberOfConcurrentTransactedReceivers="2"/>
This is the flow:
<flow name="auditJMSServiceFlow">
<http:listener config-ref="HTTP" path="/Audit/Activity" responseStreamingMode="ALWAYS" doc:name="HTTP"/>
<set-variable variableName="#['id']" value="#[message.inboundProperties['id']]" doc:name="set dynamic id"/>
<set-payload value="===TOPIC===" doc:name="Set Payload" />
<request-reply storePrefix="mainFlow">
<jms:inbound-endpoint topic="Audit.Activity" connector-ref="jmsTopicConnection" doc:name="JMS Topic Audit.Activity" exchange-pattern="request-response" durableName="audit_activity">
<jms:transaction action="ALWAYS_BEGIN" />
<!-- Not required to explicitly have this element. Mule will put this in implicitly. -->
<!-- <jms:jmsmessage-to-object-transformer displayName="JmsMsg to Object"/> -->
</jms:inbound-endpoint>
</request-reply>
<json:object-to-json-transformer doc:name="transform JMS message to JSON"/>
<json:validate-schema schemaLocation="resource://AuditMsgSchema.json" doc:name="Validate Json Schema"/>
<component class="com.baml.panther.audit.service.impl.AuditServiceImpl" doc:name="Java"/>
<default-exception-strategy>
<commit-transaction exception-pattern="com.foo.ExpectedExceptionType"/>
<jms:outbound-endpoint queue="dead.letter" connector-ref="jmsConnection">
<jms:transaction action="JOIN_IF_POSSIBLE" />
</jms:outbound-endpoint>
</default-exception-strategy>
<logger message="=== #[message.payload] received #[org.mule.util.DateUtiles.getTimeStamp('dd-MM-yyyy_HH-mm-ss.SSS')]" level="INFO" doc:name="Logger"/>
When I am running through the test I get the following error:
Any suggestions would be greatly appreciated.
Russ
For the error: Your request-reply scope is missing an outbound endpoint. You only have the inbound-endpoint (jms:inbound-endpoint). You need to provide the outbound-endpoint as well.
<request-reply storePrefix="mainFlow">
<jms:inbound-endpoint topic="Audit.Activity" connector-ref="jmsTopicConnection" doc:name="JMS Topic Audit.Activity" exchange-pattern="request-response" durableName="audit_activity">
<jms:transaction action="ALWAYS_BEGIN" />
<!-- Not required to explicitly have this element. Mule will put this in implicitly. -->
<!-- <jms:jmsmessage-to-object-transformer displayName="JmsMsg to Object"/> -->
</jms:inbound-endpoint>
</request-reply>
Not sure what your aim there but if you put just a jms:outbound-enpoint (instead of the whole request-reply block), you can send a message to the JMS topic.
The problem is that you cannot put a message source as the first message processor in a request-reply. The request reply allows you a kind of synchronous call for async protocols like JMS.
If you want to send a message to the message broker at the point where you put the request-reply just put a JMS outbound-endpoint.
If what you want to do is consume a message from the JMS topic you have to put a JMS inbound endpoint as the first message processor in a flow.

Using Mule instances in a master/slave or failover relationship

I have two Mule instances subscribed to the same topic on a queue but I only want each message consumed once.
I can achieve this by funneling messages to unique queue and processing from there, but to reduce the operational complexity I want to set up the message consumer flow running on each Mule instance to defer to one of the instances.
This would be akin to an ActiveMQ failover setup (where only one instance is running at a time and idle instances only awaken when the running instance fails to respond) or a master/slave arrangement where I would grant one of the instances command over the others. Or like a VM transport that is inter-instance instead of intra-instance.
This would need to be done without any Mule Enterprise Edition components (relying only upon Mule Community Edition components) using Mule versions 3.4. or 3.5.
I was unable to find a convenient built-in way to do this. Instead I assume that each mule instance will run on a separate box and use the server.host value to determine which instance does the processing:
<mule xmlns:redis="http://www.mulesoft.org/schema/mule/redis"
xmlns="http://www.mulesoft.org/schema/mule/core"
version="CE-3.5.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/redis http://www.mulesoft.org/schema/mule/redis/3.4/mule-redis.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
<!-- define redis instance -->
<redis:config name="redis-instance" />
<flow name="topicConsumer">
<!-- listen to redis channel (topic) -->
<redis:subscribe config-ref="redis-instance">
<redis:channels>
<redis:channel>topic.channel</redis:channel>
</redis:channels>
</redis:subscribe>
<!-- save original payload (message from Redis) -->
<set-session-variable variableName="redisPayload" value="#[payload]" />
<!-- select processor -->
<flow-ref name="topicProcessorSelector"/>
<choice>
<when expression="#[sessionVars['subscriberProcessor'] == server.host]">
<logger level="INFO" message="processing on #[server.host]"/>
</when>
<otherwise>
<logger level="INFO" message="take no action"/>
</otherwise>
</choice>
</flow>
<flow name="topicProcessorSelector" processingStrategy="synchronous">
<!-- get key -->
<redis:get config-ref="redis-instance"
key="topic_processor"/>
<!-- if no key, then add this instance as the processor -->
<choice>
<when expression="#[payload instanceof org.mule.transport.NullPayload]">
<!-- set key -->
<redis:set config-ref="redis-instance"
key="topic_processor"
expire="10"
value="#[server.host]">
</redis:set>
<set-session-variable variableName="subscriberProcessor" value="#[server.host]" />
</when>
<otherwise>
<!-- use existing key -->
<byte-array-to-string-transformer/>
<set-session-variable variableName="subscriberProcessor" value="#[payload]" />
</otherwise>
</choice>
</flow>
</mule>

Why won't a REST component not receive a call made internal to an app when multiple Global HTTP Connectors are Configured?

I'm struggling to configure and deploy to CloudHub an app with multiple Global HTTP Connectors and a REST component.
My application has two flows: one polls an RSS feed for news and posts a json representation of that feed to an http inbound endpoint in the same app (endpoint resides on second flow). The second flow receives that post, does some magic, including persisting the item to storage, and then notifies via an http outbound endpoint an external node.js web app to push the item via web sockets to active clients.
I have tried what feels like dozens of different configurations involving a variety of HTTP Global Connectors and http in and outbound endpoints, but I can't get everything to work. I currently have:
A Polling HTTP Connector
An HTTP endpoint referencing above polling http connector to get RSS Feed
One Global Connector (we'll call HTTP_ONE) to receive messages at localhost:${http.port}
An http oubound endpoint configured referencing HTTP_ONE and configured to post an activity to /api/v1/activity
An http inbound endpoint configured to receive messages for /api/v1 and a Jersey controller sitting just behind this endpoint which takes /activity.
Another Global Connector (HTTP_TWO) with an external host set as the proxy host name (e.g. somehost.somewhere.com).
An http outbound endpoint configured to post messages to somehost.somewhere.com
On my localhost, I've had to use various properties to allow for all of this activity on multiple ports on my laptop.
On CloudHub, I'm using localhost and ${http.port} everywhere except in the oubound endpoint that calls to an external web service.
I can get one flow or the other working, but not both.... My problem seems to be with the posting a given news item from the RSS feed to the Inbound HTTP Endpoint. It is sending the post to http://localhost:80/api/v1/activity, but the connector says that no such path exists (it only lists /api/v1 as an option), which makes me think that the call is not getting as far as the Jersey Controller which sits behind the Global Connector and the http inbound endpoint for /api/v1/activity. Is this behavior an inherent flaw in using the REST Component and multiple global http connectors? Also, why do we have to reference a Global HTTP Connector when making an outbound call? Why can't we use the default HTTP Connector? (Maybe the last two questions should go in a subsequent post...)
Here's most of the relevant config for the two flows:
Global Connectors
<http:polling-connector name="PollingHttpConnector" pollingFrequency="60000" doc:name="HTTP Polling" clientSoTimeout="10000" cookieSpec="netscape" receiveBacklog="0" receiveBufferSize="0" sendBufferSize="0" serverSoTimeout="10000" socketSoLinger="0" validateConnections="true"/>
<http:connector name="EduStream_HTTP" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" proxyHostname="${edustream.host}" doc:name="HTTP\HTTPS" proxyPort="80"/>
<http:connector name="EduStreamESB_HTTP" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" proxyHostname="localhost" proxyPort="${http.port}" doc:name="HTTP\HTTPS"/>
News RSS Feed Flow
<flow name="ucdNewsConsumer" doc:name="ucdNewsConsumer">
<http:inbound-endpoint address="http://news.ucdavis.edu/xml/getnews.php/rss/category/General%20Interest"
connector-ref="PollingHttpConnector" doc:name="HTTP" exchange-pattern="one-way"/>
<rss:feed-splitter/>
<rss:entry-last-updated-filter/>
<component class="edu.ucdavis.edustream.esb.news.rss.EntryReceiver" doc:name="Java"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="${http.port}" path="api/v1/activity" doc:name="HTTP" mimeType="application/json" connector-ref="EduStreamESB_HTTP" />
<logger message="Payload is: #[payload] Inbound Headers: #[headers:INBOUND:*] Outbound Headers: #[headers:OUTBOUND:*] Exception is: #[exception]" level="INFO" doc:name="Logger"/>
</flow>
Activity Publication Service -- Core Flow
<flow name="edustreamesbFlow1" doc:name="edustreamesbFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="${http.port}" doc:name="HTTP" contentType="application/json" mimeType="application/json" path="api/v1" connector-ref="EduStreamESB_HTTP"/>
<jersey:resources doc:name="REST">
<component class="edu.ucdavis.edustream.esb.activity.restapi.ActivityController"/>
</jersey:resources>
<component class="edu.ucdavis.edustream.esb.activity.restapi.JerseyResponseTransformer" doc:name="JerseyRespTrans"/>
<flow-ref name="PublishActivity" doc:name="Publish Activity"/>
</flow>
<sub-flow name="PublishActivity" doc:name="PublishActivity">
<component doc:name="ActivityService">
<spring-object bean="activityService"/>
</component>
<logger message="#[payload] #[message]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" host="${edustream.host}" port="80" path="api/v1/activity" mimeType="application/json" contentType="application/json" doc:name="HTTP" connector-ref="EduStream_HTTP"/>
</sub-flow>
I do not get why proxyHostname and proxyPort are configured on both EduStream_HTTP and EduStreamESB_HTTP connectors while the HTTP endpoints from these connectors target the same host/port as their destination address. This doesn't make any sense to me.
Are you really sure you need to use proxies?
For EduStreamESB_HTTP the answer is clearly no: you're calling CloudHub from CloudHub, so no need for a proxy.
For EduStreamESB_HTTP, maybe... but that still seems very strange.

Timed Mule Web Service Client Flow

I've searched the forums for an answer to this. I found one almost identical question, though the answer left me still wondering.
An almost identical post was found here:
Mule - Schedule a flow to consume a web service
This poster stated the problem I am having very well.
I am also new to Mule and am trying to do the very same thing. I didnt realize I needed a payload since I thought the operation specification was essentially the payload.
Notice that I have a flow that includes cxf:jaxws-client and that client specifies a URL for the service and an operation "listTest".
What other payload do i need to specify in order to actually execute the service request?
I tried to add a dummy payload to the event generator (as suggested in referenced post), and that doesnt make a difference.
When I execute the mule application, and monitor the "test auditor web service" (using wireshark) i see four requests go out for the wsdl, and i see that wsdl returned, but i dont actually see the listTest operation getting invoked.
My flow is:
<http:connector name="HTTP_HTTPS" cookieSpec="netscape"
validateConnections="true" sendBufferSize="0" receiveBufferSize="0"
receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000"
socketSoLinger="0" doc:name="HTTP\HTTPS" />
<flow name="TestAuditorClient_CheckerFlow1" doc:name="TestAuditorClient_CheckerFlow1">
<quartz:outbound-endpoint jobName="GetTestList"
repeatInterval="10000" responseTimeout="10000" doc:name="Quartz">
<quartz:event-generator-job jobGroupName="GetTestList" />
</quartz:outbound-endpoint>
<cxf:jaxws-client operation="listTest"
clientClass="server.TestService_Service" port="TestServicePort"
wsdlLocation="http://192.168.66.7:8080/TestAuditorWebApp/TestService?wsdl"
doc:name="SOAPY" />
<outbound-endpoint
address="http://192.168.66.7:8080/TestAuditorWebApp/TestService"
doc:name="HTTP" />
<logger message="Received HTTP Response #[payload]" level="INFO"
doc:name="Logger" />
<!-- <outbound-endpoint exchange-pattern="request-response" address="http://192.168.66.17:8080/TestAuditorWebApp/TestService"
doc:name="HTTP"/> -->
<file:outbound-endpoint path="C:\tmp"
outputPattern="#[function:datestamp:dd-MM-yy]_#[function:systime].txt"
responseTimeout="10000" doc:name="Output File" />
</flow>
I am not only new to mule, but as well to stack overflow. So if there was a better way for me to ask a related question, please advise and excuse.
Thanks in advance.
Instead of Quartz, you can use a poll message processor to generate the instances of ListTest you need.
Assuming this class FQDN is server.TestService.ListTest (you didn't tell), the following should work:
<flow name="TestAuditorClient_CheckerFlow1">
<poll frequency="10000">
<set-payload value="#[lt=new server.TestService.ListTest(); lt.aField='aValue'; lt]" />
</poll>
...
Notice how you can set values on the POJO directly from the expression that creates it.

editing response in mule flow before it gets sent back to the request-response endpoint

I'm kinda new to mule esb, and I can't resolve one trouble I got. Here is what happens:
I have a flow in mule 3.2.0, which receives object with request to a ws. I send it to ws with cxf:jaxws-client and. At the beginning of this flow I have vm:inbound endpoint with request-response pattern. What I want is to apply transformation to the object returned as response from the "vmIn endpoint" before it gets send back to the caller from the "vm.logService endpoint" of the flow. I actually get the response, but it's null payload. The "vm.logService" is the endpoint to witch I send MuleMessage from the Java code with MuleClient.send(url, message, properties).I've read that this should be done with the "response" block, but it seems that this is not happening.
Here is my configuration
<vm:endpoint name="vmOut" path="vmOut" exchange-pattern="request-response"/>
<vm:endpoint name="vmIn" path="vmIn" exchange-pattern="request-response"/>
<pattern:web-service-proxy
name="name"
inboundEndpoint-ref="vmIn"
transformer-refs="logging"
responseTransformer-refs="logging"
outboundEndpoint-ref="vmOut" />
<flow name="logService">
<vm:inbound-endpoint path="vm.logService"/>
<vm:outbound-endpoint ref="vmIn">
<cxf:jaxws-client serviceClass="my.WSClass" operation="operation"
enableMuleSoapHeaders="false"/>
<object-to-string-transformer/>
</vm:outbound-endpoint>
<response>
<custom transformer name="myTransformer" class="someclass" />
</response>
<flow name="genericTransformer">
<vm:inbound-endpoint path="vmOut"/>
<custom-transformer class="mypkg.GenericServiceTransformer">
</custom-transformer>
</flow>
<flow name="import">
<vm:inbound-endpoint path="vm.import" exchange-pattern="request-response"/>
<http:outbound-endpoint address="${Service}" responseTimeout="${ws.timeout}" exchange-pattern="request-response" />
<object-to-string-transformer/>
</flow>
Well, after sending with jaxws-client I have few more flows where this request message is processed, but I don't think that this is the reason why it's not working. Thanks in advance for any help
The "vm.logService" VM endpoint doesn't look request-response to me: since you don't specify an exchange pattern, it is actually one-way by default. That could explain why you don't get anything back.
Also we don't see the definition of the "vmIn" so we can't be sure it's correctly request-response, which could be another reason for not reaching the response block.
Actually: if your response block is the last element in the flow, you don't need it: it's OK if "myTransformer" is applied in the request phase since there's nothing after.
after sending with jaxws-client I have few more flows where this request message is processed
I really don't understand what you mean by that.