HTTP Webhook Strategy - Integration with Azure Service Bus
See the example integration with Azure Service Bus through webhooks.
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.
Preparing Azure infrastructure
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.
Azure Service Bus
To create Azure Service Bus, go to the Azure Portal.
Create a Service Bus called
webhookingand a queue calledwebhook.Save the Connection String that is present in the Shared access policies section.
Azure function
Create a Function App.
In this example, the function uses NodeJS and JavaScript.
Create the function locally and then deploy it to Azure.
Create a new project:
Modify the generated code.
a. Add a new dependency to
package.json:b. Execute
npm installto 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:
Configuring Emporix webhooks
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 tenanttoken- your generated Emporix access token with relevant scopesdestinationUrl- 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):
Filter events with JsonPath (HTTP)
With multiple webhook targets on the HTTP strategy, you can configure multiple entries for the same eventType. You can also add optional Jayway JsonPath filters on eventsConfiguration entries so only matching payloads are delivered.
Omit
filterto receive every event of the subscribed type.Set
filterto deliver only when the predicate matches the sanitized payload.Invalid JsonPath expressions are rejected with HTTP
400when you save the configuration.
Example:
Subscribe to custom entity updates and configure an HTTP target that only receives contract entities:
With this configuration:
An update of a custom instance with
"type": "contract"is posted to your Azure Function and forwarded to Service Bus.Updates for other custom entity types are not delivered to this endpoint.
A malformed filter such as
$[?(invalidis rejected at configuration time and is not stored.
For valid and invalid request/response samples, see the Webhook Service Tutorials.
Creating product
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.
Last updated
Was this helpful?

