HTTP Webhook Strategy - Integration with Azure Service Bus
See the example integration with Azure Service Bus through webhooks.
Last updated
Was this helpful?
See the example integration with Azure Service Bus through webhooks.
Last updated
Was this helpful?
Thanks to HTTP webhook strategy, you can choose the event service that enables communication between Emporix and external systems. This article serves as an example demonstrating how you can connect Azure Service Bus to receive events notifications from Emporix. Follow the steps to set up the connection on both sides. Adjust the actual implementation to your needs. Azure Service Bus is a messaging service that allows for communication between decoupled systems, so it can serve as a solution to connect Emporix with some other systems in your company through the webhooks functionality.
The integration between Emporix and Azure Service Bus in this example will use Azure Function that will act as a consumer of webhook events coming from Emporix. The Azure Function will receive the HTTP request, validate HMAC signature and send the request body to the given queue.
To create Azure Service Bus, go to the Azure Portal.
Follow the steps described in the Microsoft documentation .
Create a Service Bus called webhooking
and a queue called webhook
.
Save the Connection String that is present in the Shared access policies section.
Create a Function App.
Follow the steps described in the Microsoft documentation .
In this example, the function uses NodeJS and JavaScript.
Create the function locally and then deploy it to Azure.
Follow the steps described in the Microsoft documentation .
Create a new project:
Modify the generated code.
a. Add a new dependency to package.json
:
b. Execute npm install
to apply the change.
c. Provide the required information in the function's code so that the function sends the requests to Azure Service Bus. Let's take a look and analyze the function’s code:
\
Pay attention to the marked lines and provide relevant information:
i. connectionString
constant - replace the value with the connection string to your Azure Service Bus instance. Find it in the Shared access policies section in Azure Portal.
ii. queueName
constant - provide the value of the queue you created. Here, it equals webhook
just as the queue we created.
iii. secretKey
constant - provide the secret phrase for HMAC validation. You need to specify the same value in the webhooks HTTP configuration in the later steps. Here, we defined it as password123
.
iv. when HMAC validation passes, the message body is sent with the request to the queue.
Deploy the function to Azure by calling the command:
Now, prepare Commerce Engine.
Configure webhooks to send the events as HTTP POST requests. Use the following curl and provide relevant information in the placeholders:
Placeholders to fill in:
tenant
- name of your production tenant
token
- your generated Emporix access token with relevant scopes
destinationUrl
- link to your Azure Function
Subscribe to a chosen event. In this example, we subscribe to product creation event (remember to replace the values in the placeholders):
The integration is ready. To see it in action, let's create a product.
Create a product with the following curl request providing your relevant details in the placeholders:
After the product is created the event is sent. The webhook service consumes the event and sends it as HTTP request to the specified destinationUrl
, which is the Azure Function. The Azure Function receives the request and sends it to Azure Service Bus Queue.
Find more information on how to configure HMAC validation in .