我已经看到了许多使用rest创建域主题和事件订阅的例子,但是我想使用已经存在的already创建它。任何线索都会有很大帮助。谢谢
发布于 2022-02-22 07:10:18
使用java创建域主题和事件订阅的先决条件
#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令牌身份验证。参考这里
创建客户端
使用端点和访问键创建客户端
// 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();有关更多信息,请参阅这里
https://stackoverflow.com/questions/71170188
复制相似问题