[英]Connecting to Azure Event Grid and Service Bus using Java/Spring
I have a scenario where Azure ServiceBus sends events to Event Grid whenever there is a message in Azure Service bus's queue/topic.我有一个场景,只要 Azure 服务总线的队列/主题中有消息,Azure ServiceBus就会将事件发送到事件网格。 So how do I establish the connection in Java/Spring with Event Grid to receive events and also with Service Bus to pull the messages.
那么如何在 Java/Spring 中与 Event Grid 建立连接以接收事件以及与 Service Bus 建立连接以提取消息。 What are the configurations are to be done in Java/Spring to establish connections with Event Grid and Azure Service bus?
在 Java/Spring 中要进行哪些配置才能与 Event Grid 和 Azure 服务总线建立连接? Also what are the configuration that has to be done on the application side(application.yml or properties file) to include things like connection string and etc.?
此外,必须在应用程序端(application.yml 或属性文件)进行哪些配置才能包含连接字符串等内容?
Your requirement can be easily achieved by azure function app.您的要求可以通过 azure function 应用程序轻松实现。
Set the service bus queue/topic as the trigger of your function to receive messages . 将服务总线队列/主题设置为您的 function 的触发器以接收消息。
And use Azure SDK for Java to send events to event grid:并使用 Azure SDK 为 Java 发送事件到事件网格:
https://docs.microsoft.com/en-us/java/api/overview/azure/eventgrid/client?view=azure-java-stable https://docs.microsoft.com/en-us/java/api/overview/azure/eventgrid/client?view=azure-java-stable
https://docs.microsoft.com/en-us/java/api/overview/azure/messaging-eventgrid-readme?view=azure-java-stable https://docs.microsoft.com/en-us/java/api/overview/azure/messaging-eventgrid-readme?view=azure-java-stable
Azure Service Bus to Event Grid integration Azure 服务总线到事件网格集成
Service Bus can now emit events to Event Grid when there are messages in a queue or a subscription when no receivers are present.服务总线现在可以在队列中有消息时向事件网格发出事件,或者在没有接收者的情况下订阅。 You can create Event Grid subscriptions to your Service Bus namespaces, listen to these events, and then react to the events by starting a receiver.
您可以为服务总线命名空间创建事件网格订阅,侦听这些事件,然后通过启动接收器对事件做出反应。
To enable the feature, you need the following items:要启用该功能,您需要以下项目:
Check this Microsoft document for more info.查看此Microsoft 文档以获取更多信息。
Check this one to use Azure Function to connect both.选中此项以使用 Azure Function 连接两者。
Check this doc to use Logic App to connect both.检查此文档以使用Logic App连接两者。
Azure CLI: Azure CLI:
namespaceid=$(az resource show --namespace Microsoft.ServiceBus --resource-type namespaces --name "<service bus namespace>" --resource-group "<resource group that contains the service bus namespace>" --query id --output tsv
az eventgrid event-subscription create --resource-id $namespaceid --name "<YOUR EVENT GRID SUBSCRIPTION NAME>" --endpoint "<your_endpoint_url>" --subject-ends-with "<YOUR SERVICE BUS SUBSCRIPTION NAME>"
Powershell: Powershell:
$namespaceID = (Get-AzServiceBusNamespace -ResourceGroupName "<YOUR RESOURCE GROUP NAME>" -NamespaceName "<YOUR NAMESPACE NAME>").Id
New-AzEVentGridSubscription -EventSubscriptionName "<YOUR EVENT GRID SUBSCRIPTION NAME>" -ResourceId $namespaceID -Endpoint "<YOUR ENDPOINT URL>” -SubjectEndsWith "<YOUR SERVICE BUS SUBSCRIPTION NAME>"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.