使用 java sdk 的域主题和事件订阅
Domain Topic and Event Subscription using java sdk
我看过很多使用 rest API 创建域主题和事件订阅的示例,但我想使用已经存在的 azure java sdk 创建它。任何线索都会有很大帮助。谢谢
使用 java SDK
创建域主题和事件订阅的先决条件
- JDK 版本 8 或以上
- Azure 订阅
- 事件网格主题或域
按照创建主题和域的步骤 (Azure CLI)
#create Topic
az eventgrid topic create --location <location> --resource-group <your-resource-group-name> --name <your-resource-name>
#create Domain
az eventgrid domain create --location <location> --resource-group <your-resource-group-name> --name <your-resource-name>
包括所需的包
添加 BOM 文件:
将 azure-sdk-bom 添加到您的项目中以依赖于 GA 版本的库。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-sdk-bom</artifactId>
<version>{bom_version_to_target}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
并在不带版本标志的依赖部分添加直接依赖
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-messaging-eventgrid</artifactId>
</dependency>
</dependencies>
验证客户端
身份验证可以是密钥凭据、共享访问签名或Azure Active Directory令牌认证。参考 here
创建客户端
使用终结点和访问密钥创建客户端
// For custom event
EventGridPublisherAsyncClient<BinaryData> customEventAsyncClient = new EventGridPublisherClientBuilder()
.endpoint("<endpoint of your event grid topic/domain that accepts custom event schema>")
.credential(new AzureKeyCredential("<key for the endpoint>"))
.buildCustomEventPublisherAsyncClient();
使用端点和 SAS 令牌创建客户端
EventGridPublisherAsyncClient<CloudEvent> cloudEventAsyncClient = new EventGridPublisherClientBuilder()
.endpoint("<endpoint of your event grid topic/domain that accepts CloudEvent schema>")
.credential(new AzureSasCredential("<sas token that can access the endpoint>"))
.buildCloudEventPublisherAsyncClient();
参考here了解更多信息
我看过很多使用 rest API 创建域主题和事件订阅的示例,但我想使用已经存在的 azure java sdk 创建它。任何线索都会有很大帮助。谢谢
使用 java SDK
创建域主题和事件订阅的先决条件- JDK 版本 8 或以上
- Azure 订阅
- 事件网格主题或域 按照创建主题和域的步骤 (Azure CLI)
#create Topic
az eventgrid topic create --location <location> --resource-group <your-resource-group-name> --name <your-resource-name>
#create Domain
az eventgrid domain create --location <location> --resource-group <your-resource-group-name> --name <your-resource-name>
包括所需的包
添加 BOM 文件:
将 azure-sdk-bom 添加到您的项目中以依赖于 GA 版本的库。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-sdk-bom</artifactId>
<version>{bom_version_to_target}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
并在不带版本标志的依赖部分添加直接依赖
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-messaging-eventgrid</artifactId>
</dependency>
</dependencies>
验证客户端
身份验证可以是密钥凭据、共享访问签名或Azure Active Directory令牌认证。参考 here
创建客户端
使用终结点和访问密钥创建客户端
// For custom event
EventGridPublisherAsyncClient<BinaryData> customEventAsyncClient = new EventGridPublisherClientBuilder()
.endpoint("<endpoint of your event grid topic/domain that accepts custom event schema>")
.credential(new AzureKeyCredential("<key for the endpoint>"))
.buildCustomEventPublisherAsyncClient();
使用端点和 SAS 令牌创建客户端
EventGridPublisherAsyncClient<CloudEvent> cloudEventAsyncClient = new EventGridPublisherClientBuilder()
.endpoint("<endpoint of your event grid topic/domain that accepts CloudEvent schema>")
.credential(new AzureSasCredential("<sas token that can access the endpoint>"))
.buildCloudEventPublisherAsyncClient();
参考here了解更多信息