2天时间,聊今年最热的 Agent、上下文工程、AI 产品创新等话题。2025 年最后一场~ 了解详情
写点什么

Azure APIM 通过原生服务总线策略简化了事件驱动架构

作者:Steef-Jan Wiggers

  • 2025-11-11
    北京
  • 本文字数:1541 字

    阅读完需:约 5 分钟

大小:441.43K时长:02:30
Azure APIM通过原生服务总线策略简化了事件驱动架构

微软最近宣布了其 API Management(APIM)服务的一个预览功能,允许开发者使用内置策略直接向 Azure Service Bus 发送消息。该公司表示,该功能简化了组织将其 API 层连接到事件驱动的异步系统的方式。

 

以前,开发者可以在 API Management 中创建自定义解决方案,将消息发送到 Azure Service Bus。有了新的 send-service-bus-message 策略之后,他们可以直接将 API 调用的有效载荷转发到 Service Bus 的队列或主题。ApplyThing 的业务架构师 Brandon Verzuu 在 Medium博客文章中写到:

过去,如果你想让 APIM 中基于 HTTP 的 API 调用触发一个异步后端进程,通常会使用 Logic App 或 Azure Function 作为通道适配器。这个组件的唯一工作是接收消息,可能应用一些转换,然后发布到 Service Bus。

 

现在,在新策略下,当客户端向 API Management 中的 API 端点发送标准 HTTP 请求时,策略将请求作为消息发送到 Service Bus。随后,下游消费者如逻辑应用、Azure 函数或微服务会异步处理这些消息。



(图片来源:Microsoft Learn

Luke Murray 是一位 Microsoft MVP,他在一篇博客文章中描述了 send-service-bus-message 策略是什么样子的:

<policies>    <!-- Throttle, authorize, validate, cache, or transform the requests -->    <inbound>        <send-service-bus-message queue-name="your-queue" namespace="your-namespace.servicebus.windows.net">            <message-properties>                <message-property name="ApiName">@(context.Api?.Name)</message-property>                <message-property name="Operation">@(context.Operation?.Name)</message-property>                <message-property name="CallerIp">@(context.Request.IpAddress)</message-property>                <message-property name="ContentType">@(context.Request.Headers.GetValueOrDefault("Content-Type","application/json"))</message-property>                <message-property name="TimestampUtc">@(DateTime.UtcNow.ToString("o"))</message-property>            </message-properties>            <payload>@(context.Request.Body.As<string>(preserveContent: true))</payload>        </send-service-bus-message>        <return-response>            <set-status code="201" reason="Message Created" />        </return-response>    </inbound>    <!-- Control if and how the requests are forwarded to services  -->    <backend />    <!-- Customize the responses -->    <outbound />    <!-- Handle exceptions and customize error responses  -->    <on-error>        <base />    </on-error></policies>
复制代码

在 Techcommunity 的博客文章中,公司概述了使用新策略的几个用例,从通过触发多个应用程序的内部工作流进行事件通知,到通过为外部系统提供基于 REST 的端点进行合作伙伴集成,同时能够保持基于策略的控制。

 

此外,APIM 中的功能可以利用托管身份进行 API Management 和 Service Bus 之间的安全通信。此外,开发者可以通过 APIM 策略应用企业级控制,如速率限制、配额和授权,并为每个发送的消息获得 API 级别的日志记录和跟踪。

 

云解决方案架构师 Stefan van der Loop 在 LinkedIn帖子中评论说:

哦哇!我要说终于等到这个特性了!这让集成/解耦变得更容易、更健壮。现在,剩下的就是朝着两个服务的 99.99% SLA 迈进了。目前,99.8%的复合 SLA 正常运行时间对于生产场景来说仍然感觉有点不足。不过,队列可以作为故障转移的廉价替代方案。

 

关于 Azure API Management 的更多详细信息可在文档页面上找到。

 

查看英文原文:Azure APIM Simplifies Event-Driven Architecture with Native Service Bus Policy

2025-11-11 11:001

评论

发布
暂无评论
Azure APIM通过原生服务总线策略简化了事件驱动架构_云原生_InfoQ精选文章