I have a line that reads like this in my flow:
<jms:inbound-endpoint queue="${queue.name}" connector-ref="${inbound.connector}" doc:name="Inbound Endpoint">
Where the "${inbound.connector}" property refers to a string in my properties file:
inbound.connector=Active_MQ
The reason I am doing this is because the connector-ref will vary depending on the environment. Sometimes it will be an Active_MQ connector, sometimes it will be a JMS Connector.
The properties file is under src/main/resources, as it should be. I have other properties in the flow that are read from the properties file just fine, such as the "queue.name" property. However, for some reason when I try to start Mule it is returning an error saying:
NoSuchBeanDefinitionException: No bean named '${inbound.connector}' is defined.
As far as I know the connector-ref value is just a string, so this should work in theory. I don't understand this error. Is the connector-ref in fact not a string, and this approach is illegal?
Internally mule runtime creates/initializes all the connector objects(spring bean) like HTTP Connectors, DATASOURCE connectors and various other connector's when the application comes up. All these connectors are nothing but a spring beans as Mule is written on top of Springframework. So it is not possible to make it dynamic by passing in a string value where it expects a object.
Related
I would like to know what would be the best way to load the properties file in mule for the following scenario.
I have a properties file where in I set all the email related fields set in it like templates, to and from etc.
All these need to be set to a specific object along with other changes to that object so I'm planning to use a Java transformer and now I need to load all those values from that properties file and send to transformer. So what would be a best approach to work in above scenario.
Load properties in Java transformer using core java load properties
Load properties using spring context and send it to transformer and access using inbound properties
Kindly let me know if there is any other better approach other than above
First, you should be able to load the property file using spring context as shown below:
<context:property-placeholder location="somename.properties" />
Then, you can set specific property value as flow variable as shown below:
<set-variable variableName="fromAddress" value="${xyz.fromAddress}" />
Finally, you can access this flow variable in your processor class as shown below:
String fromAddress = muleEvent.getFlowVariable("fromAddress");
I will suggest to use Java load properties if these properties are only used in one Transformer. There is one more benefit out of Java load properties is that after modifying your properties file you do not need to restart the application.
In this sub-flow, how can I access from the http connector (red area) the inbound properties available at green marked area.
The scope of the inbound property is only just after the inbound endpoint or the source endpoint.
Here you should copy your inbound properties to the "flowVars" and then use it across the flow
#[flowVars.paramerterName = message.inboundProperties.'http.query.params'.parameterName]
Please make note if you want to access the HTTP properties, the syntax MEL format will be different for the Mule latest version and old version. The above one is valid for the latest Mule version and the syntax to access any property like below
#[message.inboundProperties.'http.query.params'.cityname]
where as in previous versions
#[message.inboundProperties['propertyName']].
This will depend on your inbound message source, but assuming it is an HTTP connector, use the MEL expression to access the inbound property http.query.params
#[message.inboundProperties['http.query.params']
The inbound message object is nothing but a HashMap of key-value pairs - best would be to use the debugger and select the keys you would like to access.
Here is the documentation for the Mule message, there you will find the description for the different kind of variables and properties. Inbound properties should be propagated from the main flow to the sub-flow and should still be available after the choice, excepting the case where you overwrite them or when there is an outbound-endpoint, which would overwrite them too.
I am working with Mule ESB and our goal is to use dropbox as a end point connector means to store data to dropbox(from CSV/doc or any other data source). We are able to store data to drop box but data stored in the form of object and that is not in readable format so how to convert object to string so that it can be in readable format ?
Mule already has Object to String transformer to transform String from Object :- https://developer.mulesoft.com/docs/display/current/Transformers
What I think you're after is called object serialization, and you have many choices about how to do it in a way that people can read it.
Perhaps the oldest way in java (which is the language Mule is based on) is to implement a toString() method and format your object's data as you like. Of course, this means your message payload must be an instance of a class you can make changes to. If you choose this method, you can simply add an <object-to-string-transformer /> as Anirban suggested.
Some common ways people do this, especially with Mule ESB, is to use XML or JSON to represent the information in the object. Mule includes strong support of XML and JSON. Many times, you can simply add a <json:object-to-json-transformer /> to your flow, and the payload will be converted automatically. For this to work, your payload needs to be simple types such as Maps and Lists, or an instance of a class with JAXB mappings.
Your question is a bit confusing .
if you are asking about the transformation in mule add this in your XML file <object-to-string-transformer doc:name="Object to String"/> after the dropbox component.
Let say I get a inbound variable from an http connector when I use this URL
http://x.x.x.x:8080/post?post-message=Hallo wold.
How can I use the value of the #[header:INBOUND:post-message] accross the complete flow from after the HTTP connector all the way up tp the end. Should I use the Mule Object store to write it to ram?
This post shows the scope of variables but it seem there is not one thay can flow from start to en like a session bean
https://m-square.com.au/mule-school-the-mulemessage-property-scopes-and-variables/
Kind Regards.
If you need the variable available throughout the whole flow (and
other flows reached through a flow-ref) use the invocation scope
(set-variable to set, flowVars[] to read it)
If you need it to reach other flows through a transport (e.g. VM) put
it in the outbound or session scope.
If you need it to live as long as the app is running, through
different calls, use the Mule registry (volatile, only available as
long as the app is up) or the object store (which can be configured
as persistent, to hold state even if the app goes down).
Mule Session variables are good enough to get the value throughout application.
But if you need to use the value outside your application, then you can set mule outbound properties.
There are three type of scope level variables supported by mule .
You can use flow variable if you want the variable to be accessible throughout the whole flow.
You can use session variable if you want it to be accessible form other flows through a transport barrier.
Refer this blog for getting better understanding of how different types of variables are propagated between different mule flows.
http://blogs.mulesoft.com/dev/anypoint-platform-dev/mule-school-the-mulemessage-property-scopes-and-variables/
How can I access Spring properties defined in app.properties from Mule FuncionalTestCase?
For example, in my production config I have a ${sessionExpiresInSecondsValue} passed in to a bean property. What I want to do is get this value and use it with the FunctionalTestComponent to wait for the same amount of time as that value and I don't want to harcode so the test go out of sync with the value.
The easiest is to get this bean that receives ${sessionExpiresInSecondsValue} from the registry, via MuleContext, and call getSessionExpiresInSecondsValue() on it.