NAZAR REHMAN
NAZAR REHMAN

Reputation: 179

Mule:Specifying connector properties in flow.xml using spring bean properties

Working on a mule application in which need to specify connector properties from a centralized DB. Approach i am following is collecting the data from database in a bean having an unmodifiable map, at the start of spring context.How can i specify properties of flow elements using a spring bean hashmap property in Mule.

<file:inbound-endpoint path="#[applicationConfig.configMap['mydestination']]"/>

where applicationConfig is a spring bean existing in spring-context.xml (different from flow.xml) having configMap a hashMap populated from database and having a key mydestination having value for input file endpoint. Is this correct way or is there some other way to achieve flow elements one time configuration from database.

Upvotes: 0

Views: 644

Answers (4)

NAZAR REHMAN
NAZAR REHMAN

Reputation: 179

I have achieved using spring beans hashmap property in mule flow.xml by importing springcontext.xml in flow.xml . Code

<spring:beans>
    <spring:import resource="classpath:src/main/resources/spring-context.xml"/>
   </spring:beans>  

    <file:inbound-endpoint  path="#{applicationConfig.configMap['mydestination']}" doc:name="File"/>

Upvotes: 0

Pontus Ullgren
Pontus Ullgren

Reputation: 705

I had the same requirement for a PoC we did and created Spring JDBC Placeholder Configurer.

Using this placeholder configurer you can load the properties for any JDBC datasource using your own custom SQL statement and use the normal spring placeholders ${propertyName} in the flow xml.

<bean class="com.redpill_linpro.springframework.beans.factory.config.JdbcPlaceholderConfigurer">
        <property name="dataSource" ref="dataSource" />
        <property name="selectStatement" value="SELECT value FROM properties WHERE key = ?" />
</bean>

The project is not yet available on maven central so you will have to build it and install it in your own maven repository.

Upvotes: 0

V&#237;ctor Romero
V&#237;ctor Romero

Reputation: 5115

Try to stay away from the registry, it's meant to be used at startup time and it's extremely slow if you use it from MEL, the expression will be executed every time and you´ll have to cross your fingers and hope the MEL cache does the performance work for you.

This is a very common scenario, you have a number of options but the easier one it's probably to leverage an existing spring property placeholder that then you can use with ${myPropertyName}. See here and here a tutorial on how to do exactly what you mean to do but using the open source software zuul rather than a custom made db. If it suits your needs I would follow that way.

Upvotes: 0

Nuno
Nuno

Reputation: 496

Spring beans defined in mule flows are registered in MuleRegistry. Try something similar to the following:

<file:inbound-endpoint path="#[app.registry.applicationConfig.getConfigMap().get('mydestination')"/>

However, it is not guaranteed that applicationConfig bean is registered when the file endpoint is being constructed.

Hope it helps.

Upvotes: 0

Related Questions