19 строки
6.2 KiB
YAML
19 строки
6.2 KiB
YAML
### YamlMime:JavaPackage
|
|
uid: "com.azure.messaging.eventgrid.namespaces"
|
|
fullName: "com.azure.messaging.eventgrid.namespaces"
|
|
name: "com.azure.messaging.eventgrid.namespaces"
|
|
summary: "Azure Event Grid allows you to easily build applications with event-based architectures."
|
|
classes:
|
|
- "com.azure.messaging.eventgrid.namespaces.EventGridReceiverAsyncClient"
|
|
- "com.azure.messaging.eventgrid.namespaces.EventGridReceiverClient"
|
|
- "com.azure.messaging.eventgrid.namespaces.EventGridReceiverClientBuilder"
|
|
- "com.azure.messaging.eventgrid.namespaces.EventGridSenderAsyncClient"
|
|
- "com.azure.messaging.eventgrid.namespaces.EventGridSenderClient"
|
|
- "com.azure.messaging.eventgrid.namespaces.EventGridSenderClientBuilder"
|
|
enums:
|
|
- "com.azure.messaging.eventgrid.namespaces.EventGridServiceVersion"
|
|
desc: "Azure Event Grid allows you to easily build applications with event-based architectures. The Event Grid service fully manages all routing of events from any source, to any destination, for any application. Azure service events and custom events can be published directly to the service, where the events can then be filtered and sent to various recipients, such as built-in handlers or custom webhooks. To learn more about Azure Event Grid: [What is Event Grid?][What is Event Grid]\n\nUse the client library for Azure Event Grid Namespaces to:\n\n * Publish events to Event Grid topics using the Cloud Event schema\n * Consume and settle Cloud Events.\n\n## Authentication ##\n\nIn order to send events, we need an endpoint to send to and authentication for the endpoint. The authentication can be a key credential or an Entra ID credential. The endpoint and key can both be obtained through the [Azure Portal][] or [Azure CLI][].\n\n### Endpoint ###\n\nThe endpoint is listed on the dashboard of the topic or domain in the [Azure Portal][], or can be obtained using the following command in [Azure CLI][]:\n\n```java\naz eventgrid topic show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n## Entra ID Token authentication ##\n\nAzure Event Grid provides integration with Entra ID for identity-based authentication of requests. With Entra ID, you can use role-based access control (RBAC) to grant access to your Azure Event Grid resources to users, groups, or applications. To send events to a topic or domain with a \\`TokenCredential\\`, the authenticated identity should have the \"EventGrid Data Sender\" role assigned. This authentication method is preferred.\n\n## Access Key ##\n\nThe keys are listed in the \"Access Keys\" tab of the [Azure Portal][], or can be obtained using the following command in [Azure CLI][]. Anyone of the keys listed will work.\n\n```java\naz eventgrid topic key list --name <your-resource-name> --resource-group <your-resource-group-name>\n```\n\n```java\nEventGridSenderClient client = new EventGridSenderClientBuilder().endpoint(\"your endpoint\")\n .topicName(\"your topic\")\n .credential(new AzureKeyCredential(\"your access key\"))\n .buildClient();\n```\n\n## Key concepts ##\n\n### Event Grid Namespace ###\n\nA [namespace][] is a management container for other resources. It allows for grouping of related resources in order to manage them under one subscription.\n\n### Namespace Topic ###\n\nA [namespace topic][] is a topic that is created within an Event Grid namespace. The client publishes events to an HTTP namespace endpoint specifying a namespace topic where published events are logically contained. A namespace topic only supports the CloudEvent v1.0 schema.\n\n### Event Subscription ###\n\nAn [event subscription][] is a configuration resource associated with a single topic.\n\n## Examples ##\n\n### Sending an event ###\n\n```java\nEventGridSenderClient client = new EventGridSenderClientBuilder().endpoint(\"your endpoint\")\n .topicName(\"your topic\")\n .credential(new DefaultAzureCredentialBuilder().build())\n .buildClient();\n```\n\n```java\nUser user = new User(\"John\", \"Doe\");\n CloudEvent cloudEvent\n = new CloudEvent(\"source\", \"type\", BinaryData.fromObject(user), CloudEventDataFormat.JSON, \"application/json\");\n client.send(cloudEvent);\n```\n\n### Receiving and Settling events ###\n\n```java\nEventGridReceiverClient client = new EventGridReceiverClientBuilder().endpoint(\"your endpoint\")\n .topicName(\"your topic\")\n .subscriptionName(\"your subscription\")\n .credential(new DefaultAzureCredentialBuilder().build())\n .buildClient();\n\n // Receive optionally takes a maximum number of events and a duration to wait. The defaults are\n // 1 event and 60 seconds.\n ReceiveResult result = client.receive(2, Duration.ofSeconds(10));\n\n // The result contains the received events and the details of the operation. Use the details to obtain\n // lock tokens for settling the event. Lock tokens are opaque strings that are used to acknowledge,\n // release, or reject the event.\n\n result.getDetails().forEach(details -> {\n CloudEvent event = details.getEvent();\n // Based on some examination of the event, it might be acknowledged, released, or rejected.\n User user = event.getData().toObject(User.class);\n if (user.getFirstName().equals(\"John\")) {\n // Acknowledge the event.\n client.acknowledge(Arrays.asList(details.getBrokerProperties().getLockToken()));\n } else if (user.getFirstName().equals(\"Jane\")) {\n // Release the event.\n client.release(Arrays.asList(details.getBrokerProperties().getLockToken()));\n } else {\n // Reject the event.\n client.reject(Arrays.asList(details.getBrokerProperties().getLockToken()));\n }\n });\n```\n\n\n[What is Event Grid]: https://docs.microsoft.com/azure/event-grid/overview\n[Azure Portal]: https://ms.portal.azure.com/\n[Azure CLI]: https://docs.microsoft.com/cli/azure\n[namespace]: https://learn.microsoft.com/azure/event-grid/concepts-event-grid-namespaces#namespaces\n[namespace topic]: https://learn.microsoft.com/azure/event-grid/concepts-event-grid-namespaces#namespace-topics\n[event subscription]: https://learn.microsoft.com/azure/event-grid/concepts-event-grid-namespaces#event-subscriptions"
|
|
metadata: {}
|
|
package: "com.azure.messaging.eventgrid.namespaces"
|
|
artifact: com.azure:azure-messaging-eventgrid-namespaces:1.1.0
|