Search code examples
javamuleesbenterprise

Design approach when calling the same REST service from different flows?


I'm new to Mule and I am writing a few flows that need to communicate to a back-end REST service. I'm not sure what the best design approach is.

Do I create a class that wraps the REST service, instantiate it as a spring singleton bean and inject it in to each custom Mule message processor in each of my flows?

Or is it better to just instantiate the class inside each message processor when they are called?

Or is it just another flow that interprets the mule message and calls the appropriate REST resource?

I am concerned about choosing the option that has poor performance and is difficult to maintain as the system grows.


Solution

  • Create a REST client with DevKit: http://www.mulesoft.org/documentation/display/current/Connecting+to+a+REST+API

    This will provide you with a Mule module that can be both used in Studio and as plain old Maven artifact. It will encapsulate all the client side logic and, thanks to its support for REST APIs, DevKit will do most of the work: you'll write abstract method stubs and it will generate the client code.

    Then, use choice routers and the like in your main application to call these newly created Mule elements.

    This approach will scale gracefully over time.