Over a million developers have joined DZone.

Custom Business Logic in Mule Flows—Part 1

The post is about the guidelines I use to decide which kind of component to use in a given situation.

Learn how API management supports better integration in Achieving Enterprise Agility with Microservices and API Management, brought to you in partnership with 3scale

Mule has the concept of components which are used to execute custom business logic within flows. It has excellent in-built support to define components and also has a different kinds of components that a developer can choose from. There is good documentation on the Mulesoft portal about how to use each of these types of components but I could not find guidance on choosing the right kind of component for a given use case. This post focuses what the Mule documentation calls Script components.

The post is about the guidelines I use to decide which kind of component to use in a given situation.

Mule Script components come in two broad categories.

  • Scripting language based
  • Java language based components
Scripting language based componentsJava language based components
python-component-iconruby-component-icongroovy-component-iconjavascript-component-icon[1]java-component-icon
They are concise to write because they can be directly embedded into the flow XMLs.
groovy_script
They are more verbose as there is a need to create class and method.
They are harder to unit test as they cannot be tested using JUnit tests and writing MUnit tests is more verbose and complicated compared to JUnit tests.They are easier to test as they can unit tested using simple JUnit tests.
You cannot use step through debugging.

You can use step through debugging.

I use scripting language components for small snippets of code and use Java-based components for larger pieces of business logic. I often find myself starting with a scripting language component and then later refactoring it into a Java-based component.

Within Java-based components we have three ways of defining a Java-based component

  • Mule component
  • Spring component with annotation
  • Java invoke component

In the next post I will discuss the pros and cons for each of these Java component types.

Unleash the power of your APIs with future-proof API management - Create your account and start your free trial today, brought to you in partnership with 3scale.

Topics:
mule ,java ,integration

Published at DZone with permission of Sudarshan Sreenivasan. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}