We are pleased to announce that the new Azure Event Grid libraries have reached general availability (GA). Version 4 of the Azure Event Grid packages have now been released (.NETJavaPython and JavaScript/TypeScript), following the new Azure SDK guidelines. These guidelines provide consistency across all Azure SDK client libraries while also allowing each language to follow the idioms for their respective languages.

This library is the result of months of development, design discussions, feedback, and observing developers in user studies as they worked with Azure Event Grid. In this release, we’ve simplified the API surface, added distributed tracing, and added support for publishing using the CloudEvent schema and custom event schemas.

Cross Service SDK improvements

The new Event Grid client libraries allow Event Grid developers to take advantage of the cross-service improvements made to the Azure development experience, such as:

  • Core credential types to share a single authentication approach between clients
  • A unified logging and diagnostics pipeline offering a common view of the activities across each of the client libraries

In particular, the new Event Grid libraries use the core AzureKeyCredential type for authenticating the service client.

C#

EventGridPublisherClient client = new EventGridPublisherClient(
    new Uri("<endpoint>"),
    new AzureKeyCredential("<access-key>"));

Java

EventGridPublisherClient<EventGridEvent> eventGridEventClient = new EventGridPublisherClientBuilder()
    .endpoint("<endpoint>")
    .credential(new AzureKeyCredential("<access-key>"))
    .buildEventGridEventPublisherClient();

JavaScript

const { EventGridPublisherClient, AzureKeyCredential } = require("@azure/eventgrid");
const client = new EventGridPublisherClient("<endpoint>", "EventGrid", new AzureKeyCredential("<access-key>"));

Python

from azure.core.credentials import AzureKeyCredential
from azure.eventgrid import EventGridPublisherClient
credential = AzureKeyCredential("<access-key>")
client = EventGridPublisherClient("<endpoint>", credential)

New features

In addition to the cross-service improvements, Version 4 of the library includes several new features specific to Event Grid: – Support for publishing events using the CloudEvent schema to topics which are configured to use the CloudEvent V1 schema.

C#

var cloudEvent = new CloudEvent(
    source: "/cloudevents/example/source",
    type: "Example.EventType",
    data: new MyDataModel() { A = 5, B = true });

await client.SendEventAsync(cloudEvent);

Java

// Initialize the client for use with the cloud event schema
EventGridPublisherClient<CloudEvent> publisherClient = new EventGridPublisherClientBuilder()
    .endpoint("<endpoint>")
    .credential(new AzureKeyCredential("<access-key>"))
    .buildCloudEventPublisherClient();

User newUser = new User("John2", "James");
CloudEvent cloudEventModel = new CloudEvent("https://com.example.myapp", "User.Created.Object",
BinaryData.fromObject(newUser), CloudEventDataFormat.JSON, "application/json");
publisherClient.sendEvents(cloudEventModel);

JavaScript

// Initialize the client for use with the cloud event schema
const client = new EventGridPublisherClient(
  "<endpoint>",
  "CloudEvent",
  new AzureKeyCredential("<access-key>")
);

// Send an event to the Event Grid Service, using the Cloud Event schema.
// A random ID will be generated for this event, since one is not provided.
await client.send([
  {
    type: "com.example.cloudevent",
    source: "/azure/sdk/eventgrid/samples/sendEventSample",
    data: {
      message: "this is a sample event"
    }
  }
]);

Python

client.send([
    CloudEvent(
        type="Contoso.Items.ItemReceived",
        source="/contoso/items",
        data={
            "itemSku": "Contoso Item SKU #1"
        },
        subject="Door1"
    )
])
  • Support for publishing events using a custom schema to topics which are configured to use a custom schema. Custom schema events are useful in situations where you are dealing with events that do not match either the CloudEvent or the Event Grid schema, but you would still like to use Azure Event Grid. In both Java and .NET, custom events are represented with the BinaryData type. This is a common type used across several messaging libraries in Java and .NET, including Service Bus, Event Hubs, and Storage Queues.

#azure sdk #releases

Announcing the new Azure Event Grid Client Libraries
2.35 GEEK