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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Structured Logging
  • Integrating AWS With Salesforce Using Terraform
  • Introduction To Git
  • Scaling Site Reliability Engineering (SRE) Teams the Right Way

Trending

  • Structured Logging
  • Integrating AWS With Salesforce Using Terraform
  • Introduction To Git
  • Scaling Site Reliability Engineering (SRE) Teams the Right Way
  1. DZone
  2. Data Engineering
  3. Databases
  4. API Implementation: Using Idempotent Filter to Prevent Message Twinning

API Implementation: Using Idempotent Filter to Prevent Message Twinning

Ross Mason user avatar by
Ross Mason
·
Apr. 12, 15 · Interview
Like (0)
Save
Tweet
Share
5.81K Views

Join the DZone community and get the full member experience.

Join For Free

[This article was written by Adrian Hsieh.]

 When it comes to API implementation, message “twinning” is one of those annoying pitfalls that in the worst case scenario, can lead to major problems downstream, such as duplicate orders being submitted etc. However, the client side is often not equipped to prevent duplicate messages from being sent, especially for javascript based user interface calling REST APIs, where user actions such as fat-fingering and unintentional double-clicking are virtually impossible to control.

Fortunately, the idempotent filter comes standard with Mule ESB, thus greatly simplifying the tasks of preventing message twinning for developers who are implementing REST APIs. The example here will illustrate how the filter can be used in an APIKit project. As illustrated in the application diagram below, first the message must be serialized so that the payload can be properly evaluated for comparison purpose. In this case a Byte-Array-to-String transformer is used immediately after the HTTP listener. Then, an idempotent filter is added in front of the APIkit Router for uniqueness check.

idempotent filter

Note the configuration of the idempotent filter. For APIs, the id expression has to be a combination of both the payload as well as the operation being invoked, since the same data can be valid for different operations. Therefore, we used an id expression that concatenates the request path (operation) with the payload.

<idempotent-message-filter idExpression="#[message.inboundProperties['http.request.path']+message.payload]" doc:name="Idempotent Message">
  <in-memory-store entryTTL="120000" expirationInterval="1800000"/>
</idempotent-message-filter>

Also keep in mind that for the object store configuration, the time-to-live (TTL) parameter unit is in millisecond. TTL value should be set large enough to provide effective filtering but not too large to block legitimate messages from coming through. (For high availability (HA) implementation, choose a cluster-aware object store.)

Twinning is among the more popular activities of millennials hipsters. However, when it comes to API implementation, it can be a unwanted evil that should be exorcised. And for us Gen Xers with the benefits of wisdom from life experience, we also remember that you can have fun twinning when each member of the twin is as unique as it comes…

API Filter (software) Implementation

Published at DZone with permission of Ross Mason, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Structured Logging
  • Integrating AWS With Salesforce Using Terraform
  • Introduction To Git
  • Scaling Site Reliability Engineering (SRE) Teams the Right Way

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: