首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用java进行域主题和事件订阅

使用java进行域主题和事件订阅
EN

Stack Overflow用户
提问于 2022-02-18 08:08:18
回答 1查看 129关注 0票数 0

我已经看到了许多使用rest创建域主题和事件订阅的例子,但是我想使用已经存在的already创建它。任何线索都会有很大帮助。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-22 07:10:18

使用java创建域主题和事件订阅的先决条件

  • 版本8或更高版本的JDK
  • Azure订阅
  • 事件网格主题或域:创建主题和域的步骤(Azure CLI)
代码语言:javascript
复制
#create Topic
az eventgrid topic create --location <location> --resource-group <your-resource-group-name> --name <your-resource-name>
代码语言:javascript
复制
#create Domain
az eventgrid domain create --location <location> --resource-group <your-resource-group-name> --name <your-resource-name>

包括所需的包

添加BOM文件:

azure-sdk-bom包含到您的项目中,以便依赖GA版本的库。

代码语言:javascript
复制
<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>

并在不带版本标志的依赖项部分中添加直接依赖项。

代码语言:javascript
复制
<dependencies>
  <dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-messaging-eventgrid</artifactId>
  </dependency>
</dependencies>

验证客户端

身份验证可以是密钥凭据,共享访问签名,也可以是Azure Active令牌身份验证。参考这里

创建客户端

使用端点和访问键创建客户端

代码语言:javascript
复制
// 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令牌创建客户端

代码语言:javascript
复制
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();

有关更多信息,请参阅这里

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71170188

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档