NAZAR REHMAN
NAZAR REHMAN

Reputation: 179

Mule : Calling a Rest service on mule context startup

I am having this requirement of calling a rest service for retrieving flow connector properties and populating the retrieved properties in a bean on Mule context start up. Do i need to customise mule context lifecycle?. How will populated bean be available in flow.xml? If there is failure in call of service due to any reasons, mule context should not start. Suggest best way to achieve this functionality.

Upvotes: 2

Views: 203

Answers (2)

Víctor Romero
Víctor Romero

Reputation: 5115

good work with spring-config-etcd and spring-config-jdbc. I share your point that going the spring way implementing a PropertySourcesPlaceholderConfigurer is by far the best option. There is a similar solution already in built using the zuul server, you can find the code here. I bet is easy to adapt it to your rest service.

Upvotes: 1

Pontus Ullgren
Pontus Ullgren

Reputation: 705

One way to achieve this would be to create your own placeholder configurer that calls the rest service. You can then use normal property placeholders such as §{myProperty} in your flow. Your code will be called during initialization of the mule context and if you throw an RuntimeException the context will not start.

For inspiration you can have a look at the spring-config-etcd and spring-config-jdbc projects. They both use a properties file as fallback if the property is not found in the database but you could remove that and throw an exception instead.

Upvotes: 2

Related Questions