DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Explore Salesforce OAuth Authorization Flows and Its Use Cases
  • Build a Flow Collectibles Portal Using Cadence (Part 2)
  • Build a Digital Collectibles Portal Using Flow and Cadence (Part 1)
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)

Trending

  • Cookies Revisited: A Networking Solution for Third-Party Cookies
  • Evolution of Cloud Services for MCP/A2A Protocols in AI Agents
  • AI, ML, and Data Science: Shaping the Future of Automation
  • Measuring the Impact of AI on Software Engineering Productivity

Composite Source in Mule

Learn about how and when to use the composite source scope in Mule flows to listen to multiple channels for incoming messages.

By 
Ankit Lawaniya user avatar
Ankit Lawaniya
·
Aug. 08, 17 · Tutorial
Likes (13)
Comment
Save
Tweet
Share
11.2K Views

Join the DZone community and get the full member experience.

Join For Free

Composite source is a scope available with Mule ESB which listens to multiple channels for incoming messages.

Composite source is when multiple inbound endpoints are configured to listen to the request or work as a message source. Composite source is a collection of inbound endpoints which listen for the request on different endpoints, and when any of the inbound endpoints receives a message, it triggers the flow.

We can have n endpoints, which are configured as composite source and ready to accept messages on any inbound endpoint.

How It Works

To accept incoming messages from multiple input channels, place two or more message sources (also known as receivers) into a composite source. A message entering the composite source on any supported channel triggers the processing flow.

Use Case

There can be a case where business is expecting the message to receive from the multiple sources. For example, you can receive business orders from various customers and everyone has to send a message through different channels like File Share, Web Service or REST Call, JMS, FTP or SFTP, etc. But the way of handling or business process defined for each customer is same, so we can use the composite source in such a case.

Syntax:

<composite-source>
<file:inbound-endpoint ... />
<http:inbound-endpoint ... />
<jms:inbound-endpoinT ... />
</composite-source>

Let's walk through how to use a composite source with Mule Flow.

First, search for "composite source" in Mule Palette and drag and drop it to the source region of the flow.

Now, drag and drop the file connector in message processor region. Whenever an incoming message is received by any listener, it will pass to next processor. In this case, the message will be passed to the file connector in the message processor region.

Now we can drag and drop multiple connectors under the composite source (i.e. wrap multiple connectors with the composite source). Here, we will use one HTTP Listener and one File Connector as inbound endpoints and one JMS (ActiveMQ) endpoint to receive messages from different sources. In this application, we are using choice flow control and, based on the inbound properties of the inbound endpoint, we are dynamically routing the messages.

Below are the flow diagram and code for the application.

Flow:

Image title

Choice flow control dynamically routes messages based on message payload or properties.

Code:

<mule xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
 xmlns:file="http://www.mulesoft.org/schema/mule/file" 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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
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">
<file:connector name="File" autoDelete="true" doc:name="File" />
 <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" basePath="/composite" doc:name="HTTP Listener Configuration" />
 <jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ">
  <receiver-threading-profile maxThreadsActive="200" maxBufferSize="100" />
 </jms:activemq-connector>
 <flow name="compositeSourceFlow">
  <composite-source doc:name="Composite Source">
   <file:inbound-endpoint connector-ref="File" path="/file/in/processing/" moveToDirectory="/file/data/processed" doc:name="File">
    <file:filename-wildcard-filter pattern="*.xml" caseSensitive="false" />
   </file:inbound-endpoint>
   <http:listener config-ref="HTTP_Listener_Configuration" path="/composite" doc:name="HTTP"> </http:listener>
   <jms:inbound-endpoint queue="myqueue1" connector-ref="Active_MQ" doc:name="JMS">
    <jms:selector expression="JMSPriority = 4" />
   </jms:inbound-endpoint>
  </composite-source>
  <logger level="INFO" message="#[message]" doc:name="Logger"></logger>
  <choice doc:name="Choice">
   <when expression="#[message.inboundProperties['http.query.params']]">
    <logger level="INFO" message="Message is triggered from the Http Source"
     doc:name="Logger"></logger>
    <byte-array-to-string-transformer
     doc:name="Byte Array to String" />
   </when>
   <when expression="#[message.inboundProperties['originalDirectory']]">
    <logger level="INFO" message="Message is triggered from the File Channel" doc:name="Logger"></logger>
    <file:file-to-string-transformer doc:name="File to String" />
   </when>
   <when expression="#[message.inboundProperties['JMSPriority']]">
    <logger level="INFO" message="Message is triggered from the JMS call" doc:name="Logger"></logger>
    <byte-array-to-string-transformer doc:name="Byte Array to String" />
   </when>
   <otherwise>
    <logger level="INFO" message="Message is triggered from the Unknown Source" doc:name="Logger"></logger>
   </otherwise>
  </choice>
 </flow>
</mule>

Hope this helps.

Thanks.

Keep learning.

Flow (web browser)

Opinions expressed by DZone contributors are their own.

Related

  • Explore Salesforce OAuth Authorization Flows and Its Use Cases
  • Build a Flow Collectibles Portal Using Cadence (Part 2)
  • Build a Digital Collectibles Portal Using Flow and Cadence (Part 1)
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!