How to Subscribe to Azure Event Grid from Angular Without a Backend Service Layer?

71 Views Asked by At

I'm working on an Angular application, and I need to implement Azure Event Grid subscription directly from the client-side without involving a backend service layer. I've researched various approaches but haven't found a clear solution.

Here are my requirements and what I've tried:

Requirements:

  1. Subscribe to Azure Event Grid from the Angular application.
  2. Avoid using a backend service layer for the subscription process.

What I've Tried:

  1. Explored the Azure SDK for JavaScript, but it seems primarily designed for Node.js.

  2. Investigated using @azure/eventgrid library, but encountered issues related to the lack of support in a browser environment.

Question Details:

  1. Is it possible to subscribe to Azure Event Grid directly from an Angular application without relying on a backend service?
  2. Are there any client-side libraries or methods available for handling Azure Event Grid subscriptions in a browser environment?
  3. If a backend service layer is unavoidable, what is the minimal setup required to achieve Azure Event Grid subscription with Angular?

Code Snippet tried in nodejs:

  const eventSubscriptionInfo = {
    destination: {
      endpointType: "WebHook",
      endpointUrl: endpointUrl,
    },
    filter: {
      isSubjectCaseSensitive: false,
      subjectBeginsWith: "",
      subjectEndsWith: "",
      includedEventTypes: ["All"],
    },
  };
  const credential = new DefaultAzureCredential();
  const client = new EventGridManagementClient(credential, subscriptionId);
  const result = await client.eventSubscriptions.beginCreateOrUpdateAndWait(
    scope,
    eventSubscriptionName,
    eventSubscriptionInfo
  );

Environment Details:

Angular version: Angular 15 Azure SDK: 5.0.0

1

There are 1 best solutions below

0
Ostrich96 On

Data for an event gird event is received as a JSON object in the body of an http request, and unfortunately there is no way to handle HTTP request on the client side. thus you will need a server app that will listen for those HTTP request and emit HTTP responses.