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

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Power BI Embedded Analytics — Part 3: Power BI Embedded Demo
  • DGS GraphQL and Spring Boot
  • Concourse CI/CD Pipeline: Webhook Triggers
  • Auto-Instrumentation in Azure Application Insights With AKS

Trending

  • Analyzing Techniques to Provision Access via IDAM Models During Emergency and Disaster Response
  • How to Merge HTML Documents in Java
  • What’s Got Me Interested in OpenTelemetry—And Pursuing Certification
  • Monoliths, REST, and Spring Boot Sidecars: A Real Modernization Playbook
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Webhooks in Mule

Webhooks in Mule

This article outlines the concept of webhooks, as well as how to make a webhook callback and implement webhooks in Mule.

By 
Niladharshini Ayyasamy user avatar
Niladharshini Ayyasamy
·
Aug. 19, 22 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
5.6K Views

Join the DZone community and get the full member experience.

Join For Free

What Are Webhooks?

A webhook is a lightweight API that powers one-way data sharing triggered by events. In other words, webhooks are automated messages or triggers that an application sends whenever a desired event occurs.

For example, say there’s a movie information application. We need to know whether any new movie has been released recently. In case of API implementation/polling, we need to keep making requests to the movie application to know the details at any point of time. Even if there are no new movie releases, we need to be sending requests to the application again and again to keep checking for new releases which is redundant.


This is where the webhook comes into picture. With webhook implementation, the movie application will make a call to the webhook in the application it is hooked to with required information whenever there’s an update. It means that the movie application will send a notification to the user whenever there’s a new movie release, making the process simple.


Technically, webhooks are "user-defined callbacks made with HTTP," according to Jeff Lindsay. The webhook URL is generally a HTTP POST implementation. Whenever a desired event occurs at a hooked application, a HTTP POST request will be made to the webhook URL and the application that has hosted the webhook will take necessary actions. The application hosting the webhook may have facilities to subscribe to and unsubscribe from the webhook to accommodate multiple applications as well.

Webhooks in Mule

When dealing with webhooks in Mule, there are two aspects to it. One is to make a webhook callback, and the other is to implement a webhook using Mule.

1. Webhook Callback from Mule Application

As discussed earlier, webhooks are generally HTTP implementations. It is usually POST, but in some cases, it is a GET implementation. Calling a webhook from a Mule app is similar to sending a notification or an email. If this callback should not have an impact on the actual implementation of your application, it has to be carried out asynchronously. To achieve that, you can carry out this operation in an Async block. A simple HTTP Request component can be used to make the HTTP POST/GET call to the webhook URL with the required headers and payload.

Here, we’ll be seeing how to call a Slack webhook from a Mule application. Kindly refer to this link to create an incoming webhook in Slack. Now we have a webhook URL similar to https://hooks.slack.com/services/******/*******/*******.

In the below application, the Slack webhook is hit whenever the order quantity is greater than 1000.


The result would be the order numbers being posted in the Slack channel whenever the order quantity is greater than 1000.

Here, a basic example has been explained, but the Anypoint platform comes with more than 250 out-of-the-box connectors to integrate with various systems. Leverage the connectors and create Mule Flows to consume the events from the source system and push the messages to registered callback URLs. 

We’ve made only one webhook callback. If we need to make multiple callbacks to different webhooks in case of an event, we can have a subscription model implemented with facilities to subscribe to and unsubscribe from the event. Implement this as a REST API with endpoints to subscribe and unsubscribe. Once we have that, we can make a callback to all the subscribers whenever a desired event occurs.

2. Webhook Implementation

You can develop a webhook in Mule and provide the URL for apps/users to make a callback to whenever a desirable event occurs. Developing a webhook is similar to that of a REST API. Firstly, prepare an API specification for the webhook with the endpoint and acceptable input structure. You can have a POST/GET endpoint based on the requirement. Then, implement the same using Anypoint studio with the operations to be performed whenever there’s a webhook callback. The webhook implementation can be a part of a certain application or you can have a standalone implementation for webhook as well. 

In the below example, we have a simple webhook implementation where whenever a POST request is made to the HTTP listener at /webhook with acceptable input, it will perform a certain set of operations.

To follow API-led connectivity, you can first have the API for Webhook designed, implemented, registered and then made discoverable. Once the webhook is ready, the webhook URL can be shared with users along with the acceptable input payload format for the request.

Webhook application

Published at DZone with permission of Niladharshini Ayyasamy. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Power BI Embedded Analytics — Part 3: Power BI Embedded Demo
  • DGS GraphQL and Spring Boot
  • Concourse CI/CD Pipeline: Webhook Triggers
  • Auto-Instrumentation in Azure Application Insights With AKS

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!