Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Mule Dismantle, Component Mule Example

DZone's Guide to

Mule Dismantle, Component Mule Example

· Integration Zone
Free Resource

Discover how Microservices are a type of software architecture where large applications are made up of small, self-contained units working together through APIs that are not dependent on a specific language. Brought to you in partnership with AppDynamics.

The component is program that has some part of logic which we can use in mule flow. We can use programming language like java, Expression language, java script, python etc., for a component.

Create a mule flow, add http end point to it, with the below configuration

Host: localhost

Port: 8082(port should be unique in the flows)

Create a java class inside src/main/java folder of the mule project

public class PrintPayload {
     public void method1(String args) {
         System.out.println("String as args");
         System.out.println(args);
     }
     public void method2(byte[] values) {
         System.out.println("byte as args");
         System.out.println(values);
     }
}

In the flow add a java component, refer the PrintPayload class in the class name: property of the java component.

Add string to bytearray transformer

Again add the java component, refer the PrintPayload class in the class name property.

The flow will look like below

And the flow will have the below configuration.

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
      <flow name="ComponentFlow1" doc:name="ComponentFlow1">
          <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/>
          <component class="com.classes.PrintPayload" doc:name="Java"/>
          <string-to-byte-array-transformer doc:name="String to Byte Array"/>
          <component class="com.classes.PrintPayload" doc:name="Java"/>
      </flow>
</mule>

Run the application.

In the browser hit the url:

http://localhost:8082/?name=kasi

you will get the following output:

String as args

/?name=kasi

byte as args

[B@23a1f067

Mule calls the appropriate method based on payload type.

Discover the six challenges and best practices in managing microservice performance, brought to you in partnership with AppDynamics.

Topics:

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 }}