0
votes

I'm currently working on a project where I need to consume a third-party Webhook into my application. The issue is, this third-party service doesn't allow me to pick which events to push to my application through this Webhook, so I'll have to respond to all of them even if they are mostly useless, and if I need to expand on my application or divide it into microservices, I would be streaming the same data to all services even if they have different needs. Also, I would be facing data loss in case of issue with my application server.

The solution would be to use an Event Broker, which would collect all events from the Webhook, respond to the provider with a 200 OK status code, push the event to a specific topic which will be stored until all the concerned subscribed services receive that data.

I'm looking for a fully managed service in Azure, so far I've come across Azure Event Grid, Azure Event Hub and Azure Service Bus.

I wanted to know about the feasibility of this scenario, and if I can stream directly from a Webhook to one of these Azure services.

2

2 Answers

1
votes

No, afaik you cannot stream directly into those service. You will need to setup something that accepts the webhook and sends it to one of those listened service.

However, what I would do is create an http triggered azure function. You should be able to configure the webhook to post to the function.

Once you got your function setup you can create some logic there to route the message to the proper channels based on its content. Now that could be an application of yours, a Service Bus Queue, Azure Storage Queue or Event Grid. I would not recommend an Event Hub as it is less suited for this specific purpose.

1
votes

In the case of consuming a third-party events without guarantee their in order processing and the webhook payload is an array, the Azure Event Grid can be consumed your third-party webhook directly.

The following screen snippet shows this example:

enter image description here

The above integration is based on the Custom Topic Endpoint with a CustomInputSchema. The Custom Topic Endpoint sends a response back to the webhook with the following HTTP response code:

Success                                200 OK
Event data has incorrect format        400 Bad Request
Invalid access key                     401 Unauthorized
Incorrect endpoint                     404 Not Found
Array or event exceeds size limits     413 Payload Too Large

The AEG model distributing an event in the loosely decoupled Pub/Sub manner with a reliable and retry delivery to the subscriber based on its subscriptions. The AEG subscription represents a logical connectivity between the source of the interest and consumer. It is a set of metadata describing by consumer what, where and how.

Basically there are two delivery patterns such as:

  • Push-PushAck where the event is pushed to the subscriber handler for its business processing and the result is back to the AEG e.g. Web Hook (Azure Fuction) and Hybrid Connection.

  • Push-PullAck where the event is reliable delivered to the subscriber and the delivery response is returned back to the AEG. The event must be pulled out from this delivery target for its business post-processing, e.g. Service Bus Queue, Storage Queue and Event Hubs.

UPDATE:

For creating a custom topic endpoint with a CustomInputSchema can be used for example the REST API The following is an example of the payload PUT request:

{
   "location": "westus",
   "properties": {
   "inputSchema": "CustomEventSchema",
   "inputSchemaMapping": {
     "properties": {
       "id": {
         "sourceField": null
       },
       "topic": {
         "sourceField": null
       },
       "eventTime": {
         "sourceField": null
       },
       "eventType": {
         "sourceField": null,
         "defaultValue": "notification"
       },
       "subject": {
         "sourceField": null,
         "defaultValue": "/webhook/events"
       },
       "dataVersion": {
         "sourceField": null,
         "defaultValue": "1.0"
       }
     },
     "inputSchemaMappingType": "Json"
   }
 }

}

The above CustomInputSchema enables to use any input event schema for this Custom Topic endpoint. That's very nice feature of the AEG. The "bad news" is that the events must be in the array included also a single event. I hope, that the AEG team will make an improvement for custom and domain topics when the single event can be published also as a JObject (no inside of the array).

For bypassing an input event schema via AEG eventing model, the subscriber (consumer of the source event interest) must declared a DeliverySchema = CustomInputSchema. The default output event schema is the EventGridSchema.

The following examples show an event message published to the custom topic with above CustomInputSchema and delivered to the subscribers using a CustomInptutSchema and the other one with the EventGridSchema.

Fire Event to the Custom Topic Endpoint (array of event(s)):

[
  {
    "abcd": 12345
  }
]

Subscriber with DeliverySchema = CustomInputSchema:

{
  "abcd": 12345
}

Subscriber with DeliverySchema = EventGridSchema (default schema):

{
  "id": "f92a5dbf-d206-4e61-ac1e-7498c543039a",
  "eventTime": "2019-07-14T07:19:00.3969337Z",
  "eventType": "notification",
  "dataVersion": "1.0",
  "metadataVersion": "1",
  "topic": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rk2012/providers/Microsoft.EventGrid/topics/testerTopic8",
  "subject": "/webhook/events",
  "data": 
    {
      "abcd": 12345
    }
}

Note, that the events can be filtered (selected) for each subscriber based on its subscription properties in the loosely decoupled Pub/Sub manner. In other words, subscriber can subscribed to the AEG eventing model any time via its subscription where is declared a specific source interest, e.g. topic, subject, event data, etc., mechanism of the delivery, retrying, deadlettering, etc.