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 (.NET, Java, Python 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.
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:
In particular, the new Event Grid libraries use the core AzureKeyCredential
type for authenticating the service client.
EventGridPublisherClient client = new EventGridPublisherClient(
new Uri("<endpoint>"),
new AzureKeyCredential("<access-key>"));
EventGridPublisherClient<EventGridEvent> eventGridEventClient = new EventGridPublisherClientBuilder()
.endpoint("<endpoint>")
.credential(new AzureKeyCredential("<access-key>"))
.buildEventGridEventPublisherClient();
const { EventGridPublisherClient, AzureKeyCredential } = require("@azure/eventgrid");
const client = new EventGridPublisherClient("<endpoint>", "EventGrid", new AzureKeyCredential("<access-key>"));
from azure.core.credentials import AzureKeyCredential
from azure.eventgrid import EventGridPublisherClient
credential = AzureKeyCredential("<access-key>")
client = EventGridPublisherClient("<endpoint>", credential)
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.
var cloudEvent = new CloudEvent(
source: "/cloudevents/example/source",
type: "Example.EventType",
data: new MyDataModel() { A = 5, B = true });
await client.SendEventAsync(cloudEvent);
// 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);
// 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"
}
}
]);
client.send([
CloudEvent(
type="Contoso.Items.ItemReceived",
source="/contoso/items",
data={
"itemSku": "Contoso Item SKU #1"
},
subject="Door1"
)
])
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