How to send a message to Azure Service Bus when an entity is created or updated?
To be able to send a message to Azure Service Bus you need to have a:
- Webhook template set up according to the service bus endpoint.
- User business rule configured to trigger when an entity object of specific type is created or updated.
- The user business rule must define an action of type WEBHOOK, pointing to the code of the webhook template.
For the purposes of the example, the ServiceActivities entity is used, but you can do it with any entity of your needs.
Below is an example of what the webhook template should contain.
|Attribute name||Attribute value|
|Name||Azure Service Bus - service activity updates|
|URL||https://<serviceNamespace>.servicebus.windows.net<queuePath | topicPath>/messages|
|Notes||Sends a message to Azure Service Bus queue when a service activity is created or updated.|
<serviceNamespace>, <queuePath> OR <topicPath> are specific to your service bus endpoint's configuration.
<authorizationToken> as the name suggests, is an authorization token that can be:
Azure AD JWT token - in case registration of an application.
Authorization: Bearer <Azure AD JWT token>
SAS token - in case of a shared access key.
Authorization: SharedAccessSignature sr=<NAMESPACE NAME>.servicebus.windows.net&sig=<SIGNATURE>&se=<TOKEN EXPIRY INSTANT>&skn=<SHARED KEY NAME>,
where the <SIGNATURE> is to be calculated as follows (pseudocode):
urlencode(base64(hmacsha256(urlencode('https://<NAMESPACE NAME>.servicebus.windows.net/') + "\n" + '<TOKEN EXPIRY INSTANT>', '<SHARED ACCESS KEY>')))
For how you can generate a SAS token in different programming languages, visit the following link: Generate SAS token
The Body is an interpolated string, formed in JSON format. When evaluated, it will contain the data for the entity in the context of which the business rule is executed.
User business rule
The webhook template can't be used as a standalone thing. This is simply a template that in this particular case must be evaulated in the context of a service activity when the latter is created or updated. Therefore, a user business rule needs to be defined.
|Event type||Event parameter||Execution priority|
|Action No||Action type||Parameter1 type||Parameter1 value|
This seems pretty straightforward. A business rule that will trigger on AGGREGATECLIENTCOMMIT event and will execute a WEBHOOK action with code sb_service_activity_01.