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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Apache Airflow Configuration and Tuning
  • How To Generate Scripts of Database Objects in SQL Server
  • What Are SpeedUp and ScaleUp in DBMS?
  • What Does Synchronization With Asyncio Look Like

Trending

  • New York City Taxi Trips: Putting Neo4j and DuckDB to Work
  • Member Spotlight: Shai Almong
  • Introduction to Error Prone: How to Catch Bugs at Compile Time
  • Architecture Review Boards for Generative AI: A Framework for Governance, Risk Management, and Responsible Adoption

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. Scheduling Tasks With Polling in Mule ESB

Scheduling Tasks With Polling in Mule ESB

Polling is a integral part of enterprise integration. Since Mule ESB is an integration platform, it supports polling — and it does so in various ways.

By 
Harish Kumar
·
Feb. 23, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
17.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Polling, as the name suggests, is an engineering pattern in which you write or create a task once and then schedule it to run at a specific frequency. This frequency can be anywhere from milliseconds to days.

Polling is a integral part of enterprise integration. Since Mule ESB is an integration platform, it supports polling — and it does so in various ways. Today, I will be showing you how to poll any of your resources using the polling component of Mule ESB.

Before we start, below are some use cases in which polling can be of use.

  • Creating reports on some data periodically.
  • Synchronizing data between two systems by polling one and sending it to the other.
  • Fetching data from your cloud applications (i.e., CRM, ERP, etc.) for further processing.

I will be using SalesForce as a poll example and creating a polling batch where I will be continually polling accounts from SalesForce and printing them to logs.

As soon as a new account is created in SalesForce, we will get it in our flow and then log it in the logger. We can very easily replace this logger with some other system, like DB or some kind of BI process where this data could be of use.

I am not going to cover how setup salesforce connector for that please refer to my other article or watch my YouTube tutorial for SalesForce.

Flow

screen-shot-2016-10-08-at-14-53-20

As is clear from the image above, our flow is very simple. We have created a poll component, and in the scope of poll is the SalesForce connector. Our polling component will fire repeatedly based the frequency we set and will fire the SalesForce connector.

In this polling component, we will be setting a watermark that will be persisted by the polling component in our object store and will be updated every time the SalesForce connector returns some result.

Polling Component

screen-shot-2016-10-08-at-14-53-39

Above, I have set the frequency to be fired in every 30 seconds. In the Watermark section, I am setting the name of watermark. This name will be available to us as flow variable, can be used in every run of flow, and will be updated by polling component with the value of CreatedDate at the end of each execution of flow.

default.last.creation.date = 2005-10-08T01:02:03Z

Once we reach the last row in SalesForce and there are no more results, then the process part of flow will not be executed until unless new data is created in SalesForce. We will get the newly created data in the next run of flow, i.e., after 30 sec.

Using Watermark

screen-shot-2016-10-08-at-14-54-16

Here, I am using the watermark set in the polling component to query SalesForce to get the latest values by using flowVars.lastCreationDate.

Testing

screen-shot-2016-10-08-at-15-21-59

As you can see in the first run, we get 19 records. In the second run, I got next 6. In the end, once all records are consumed, we start getting empty data and no more records. This message is displayed:

Watermark value will not be updated since poll processor returned no results.

One more important thing to remember is that you can only use watermark if the processing strategy of your flow is synchronous.

screen-shot-2016-10-08-at-15-39-13

Complete flow XML:

<flow name="sfdc-batch-accountFlow" processingStrategy="synchronous">
	<poll doc:name="Poll">
		<fixed-frequency-scheduler frequency="15" timeUnit="SECONDS" />
		<watermark variable="lastCreationDate" default-expression="${default.last.creation.date}" selector="LAST" selector-expression="#[payload.CreatedDate]" />
		<sfdc:query config-ref="Salesforce__Basic_Authentication" query="dsql:SELECT AccountNumber,BillingCity,BillingPostalCode,CreatedById,CreatedDate,LastModifiedById,LastModifiedDate,Name  FROM Account where CreatedDate&gt;#[flowVars.lastCreationDate]" fetchSize="10" doc:name="Salesforce" />
	</poll>
	<logger message="Payload size is #[payload.size()] and watermark is #[flowVars.lastCreationDate]" level="INFO" doc:name="Logger" />
	<json:object-to-json-transformer doc:name="Object to JSON" />
	<logger message="#[payload]" level="INFO" doc:name="Logger" />
</flow>

That is all. If you liked this tutorial, do let me know.

Polling (computer science) Enterprise service bus Database Flow (web browser) Task (computing) Scheduling (computing)

Opinions expressed by DZone contributors are their own.

Related

  • Apache Airflow Configuration and Tuning
  • How To Generate Scripts of Database Objects in SQL Server
  • What Are SpeedUp and ScaleUp in DBMS?
  • What Does Synchronization With Asyncio Look Like

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook