Start/Stop Flow/Endpoint in Mule 3.3.0 - mule

I need to programmatically start or stop a flow or endpoint from another flow. Can this be done? Is there risk of message loss?
<flow name="control>
<vm:inbound-endpoint path="in">
<script:component>
<!-- start/stop -->
</script:component>
</flow>
<flow name="startable-stoppable>
<any-transport:inbound-endpoint/>
<component/>
</flow>

After some research I've found that the best option in my case is to start/stop the connectors associated with the endpoints I want to control.
<script:component>
<script:script engine="groovy">
muleContext.getRegistry().lookupConnector('connectorName').start() // or stop()
</script:script>
</script:component>
A disadvantage of this approach is that all the endpoints associated with the connector will be affected. If this is a problem, every endpoint should have its own connector.

You can control the lifecycle of Mule moving parts with JMX: use JConsole to find out what MBean you need to access from your scripted component.

Related

Call a File Inbound Endpoint via Http endpoint - Set XML as payload and update in IBM MQ

I am designing an application flow where I have to read a file (XML File) and put the data into IBM MQ (Queue). Do I need to create an HTTP request that will trigger the File read and update queue, otherwise how do I perform this task.
Currently I am creating an HTTP Request and connecting it to WMQ but I am getting NULL data into the Queue. Basically the payload is NULL.
This is the data I read when I browse the Queue:
sr.org.mule.transport.NullPayload1.L5U���...xp
Try like this:
Whenever you use File connector at any other place than the beginning of the flow, then it becomes an outbound endpoint.
For using File as an inbound endpoint to retrieve any file, you must use it in the beginning of some flow & keep the flow in stopped state initially as:
<flow name="filePickupFlow" initialState="stopped">
<file:inbound-endpoint path="src/main/resources/input" responseTimeout="10000" doc:name="File"/>
<wmq:outbound-endpoint queue="gh" doc:name="WMQ" connector-ref="WMQ"/>
</flow>
For your case just change the path with your required file location.
Then for further calling it via http, create another flow with http endpoint & use an Expression component to start the flow containing file inbound endpoint call as :
<expression-component doc:name="Expression">
app.registry.filePickupFlow.start();
</expression-component>
Then if you wish to stop it after it completes processing, you can again use an Expression component as:
<expression-component doc:name="Expression">
Thread.sleep(5000);
app.registry.filePickupFlow.stop();
</expression-component>
Thread.sleep() is used here just to give some time gap between flow start & stop to let the flow operation complete. You can add some other thing for maintaing this time gap or set the time according to your own usage.
I guess this is what you were looking for.
Regards,
JJ
If you want to access the file component on-demand( Whenever you access the HTTP, only then File component needs to access), use Mule Requester in the place of file component which do the same work.
<mulerequester:config name="Mule_Requester" doc:name="Mule Requester"/>
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" basePath="test2" doc:name="HTTP Listener Configuration"/>
<flow name="httpFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<mulerequester:request config-ref="Mule_Requester" resource="file://C:/in" doc:name="Mule Requester"/>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="**payload:*#[payload]" level="INFO" doc:name="Use WMQ here instead of Logger"/>
</flow>
Link to refer: https://github.com/mulesoft/mule-module-requester/blob/master/mulerequesterdemo/src/main/app/MuleRequesterDemo.xml
Instead of HTTP, you can also schedule job trigger using Poll component based on your requirement. Hope this helps.
You wanted to used file connector as inbound endpoint but actually using as outbound endpoint. Check your configuration xml file for file connector.
There are many ways for reading file as inbound like file connector, Poll scope or Quartz connector. You can use anyone of these as per you requirement. The simplest flow is as
<flow name="testfixedFlow">
<file:inbound-endpoint path="tmp" connector-ref="File" responseTimeout="10000" doc:name="File"/>
<wmq:outbound-endpoint queue="xyz" connector-ref="WMQ" doc:name="WMQ"/>
</flow>
But if you want to get resource in between the flow you can use Mule requester
Hope this helps.

How should we be organizing our mule imports in order to maximize loading efficiency and for modularity for munit testing?

We currently have our mule projects organized where we have our mule flows in several flow files. We find that this helps in allowing us to reuse flows. However, it has an added side-effect. By having dependencies amongst other flow files, we are finding that our munit tests now have to load an extensive number of flow files that slows up our munit tests because we have to load many more files. We also don't want to stick our flows into one huge file either.
We want to know if there is a happy medium or a strategy with how we should be splitting our flow files so that it minimizes the impact of performance when it comes to tests and application loading?
Thanks,
Juan
I suggest that you use a general global configuration xml, where you place all your configurations and endpoint connectors. That way, you will only load the global.xml and not every other flow you are referencing.
Global.xml contains:
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<http:request-config name="REST_Request_Configuration" host="localhost" port="80" basePath="example" doc:name="HTTP Request Configuration"/>
<http:request-config name="REST_Request_Configuration2" host="google.com" port="80" doc:name="HTTP Request Configuration" basePath="/translate/v2">
On your test suite you only need to load one classpath/xml:
<spring:beans>
<spring:import resource="classpath:global.xml"/>
<spring:import resource="classpath:workflow_you_are_testing.xml"/>
</spring:beans>
Hope this helps.
I'd define the default mule-config.xml, with the connector configurations and flow file for each task in the project. Doesn't necessarily mean each flow file will contain single flow but flows related to same task conainining sub-flows or private flows as needed. However, the flow functionality which is reuseable like alert emails, database operations, put that in separate commons-config.xml flow file.
For unit-testing, I'd create another mule-test-config.xml under src/test/resources to contain mock connectors like database or any other. The connectors to use as it is like http or some other, copy them as it is to mule-test-config.
Now to test particular flow, you'd need flow file + mule-test-config + commons-config (if any shared flow)

Alternative way for dynamic inbound endpoint for Mule 3

I am working on migrating my Mule 2 project to Mule 3. However, since Mule 3.3 stop supporting dynamic inbound endpoint, I need to find an alternative way to rewrite my inbound endpoint.
Basically, I want to make http call to get some data from specific websites by using current system time as the query parameter. My codes in mule-config.xml is like the following
<flow name="RetrieveNewsService">
<http:inbound-endpoint host="www.awebsite.com" port="80" path="datacenter/someData.asp?category=1&date=[function:dateStamp:MMddyyyy]" connector-ref="RetrieveNewsPollingHttpConnector" exchange-pattern="one-way" />
//doing some process
</flow>
I feed current time for "path" part, and it works perfect in Mule 2, but get the exception mentioning about dynamic inbound endpoint is not supported anymore.
Anyone has any idea how to rewrite the dynamic path for inbound endpoint and what is the purpose they decide to stop this feature? Thanks for your time!
You can use a poll on an HTTP outbound-endpoint as demonstrated here:
<flow name="RetrieveNewsService">
<poll frequency="10000">
<http:outbound-endpoint method="GET" host="localhost"
port="8082" path="test?dtm=#[server.dateTime.format('MMddyyyy')]"
exchange-pattern="request-response" />
</poll>
//doing some process
</flow>
PS. No idea why.

Mule CXF consuming webservice

i am creating one webservice in mule using cxf:jaxws-service. This is the url :http://localhost:65042/InsertDocService/InsertDoc, i am ablie to generate WSDL file, but i want to consume this service in mule using cxf:jaxws-client.
<flow name="documentumclientflowFlow1" doc:name="documentumclientflowFlow1">
<inbound-endpoint address="http://localhost:65042/InsertDocumentumService/InsertDocumentum" doc:name="Generic"/>
<cxf:jaxws-client operation="insertDocumentum" serviceClass="com.integration.IDocumentumInsert" port="80" mtomEnabled="true" enableMuleSoapHeaders="true" doc:name="SOAP"/>
<outbound-endpoint address="http://locahhost:65042/InsertDocumentumService/InsertDocumentum" doc:name="Generic"/>
</flow>
if i invoke this, it's going to Service project and getting erorr like"org.apache.cxf.interceptor.Fault: No such operation: (HTTP GET PATH_INFO: /InsertDocumentumService/InsertDocumentum)". Please any one suggest me how can i solve this issue and how can i consume this service.
Besides the type (locahhost instead of localhost), it looks like you're trying to use the same address in the outbound endpoint than in the inbound one. I don't think this is what you want to do, as it will lead to a looping re-entrant call that will eventually exhaust the pool threads, block, time out and die in a fire.
So what do you want to do with "documentumclientflowFlow1"? It is unclear from your question.

Mule Community Edition and Blocking retry policy

i would like to define some sort of "retry policy" for a custom componenet i built, meaning retry on the initiailise function of the compoenent.
Is that supported by some XML tag (retry policy??) or would i have to implement the retries inside the initialise function itself? (which would mean i would have to handle the threads and stuff if i want to handle it like the "blocking" property of the EE edition)
And suppose there is some sort of retry attempts - what would happen if the component is still attempting to reinitialise while an inbound endpoint event is triggered? (or would that endpoint not register until the flow manages to start the component?)
In case i wasnt clear - this is the short example:
<flow>
<quartz:inbound-endpoint jobName="eventTimer">
<quartz:event-generator-job />
</quartz:inbound-endpoint>
<component>
<singleton-object class="com.SomeComponent" />
</component>
<vm:outbound-endpoint path="ChatMsgs"
exchange-pattern="one-way" />
</flow>
I'd like to set a "non-blocking" retry policy on the component and i would like the flow not to start until the component manages to initialise, is that asking too much of mule? :)
Thanks in advance
Non-blocking retry policies are now part of CE (since 3.2.0).
To have your component integrated with Mule's lifecycle and retry policies, I suggest you develop it as a Mule module using DevKit (see "Mule’s Lifecycle Support" in http://blogs.mulesoft.org/introducing-the-new-devkit/). Though marketed as an "API connector toolkit", DevKit does way way more things...
Of course, this would make your component Mule specific but with the benefit of making it a first-class citizen of Mule's infrastructure.