简体   繁体   English

Azure API管理是否可以同步发布到Azure Service Bus?

[英]Is it possible for Azure API Management to synchronously post to Azure Service Bus?

I am converting a monolithic application to microservices. 我正在将单片应用程序转换为微服务。 I have set up an API Management layer and a Service Bus all within a Service Fabric. 我已经在Service Fabric中设置了API管理层和Service Bus。 The idea is to use messages to communicate to the microservices so they do not know about eachother. 想法是使用消息与微服务通信,以使它们彼此之间不了解。

When one microservice needs information it posts a message to the service bus and it gets fulfilled and a reply is sent and correlated. 当一个微服务需要信息时,它会将一条消息发布到服务总线上,并得到满足,然后发送并关联一个回复。

The only problem is that the API Management posts the message to the service bus and returns without waiting for a reply therefore the client does not get a response. 唯一的问题是,API管理将消息发布到服务总线并返回而无需等待答复,因此客户端无法获得响应。

Is there a way to have the API Management wait for a reply? 有没有办法让API管理等待答复?

Would this need a sort of broker service in-between? 两者之间是否需要某种经纪人服务?

Is it better to just have a REST layer on each microservice that the API Management could call but then the services would use the service bus? 在每个微服务上都具有一个REST层(API管理可以调用​​但服务随后将使用服务总线)是否更好?

Thanks for any help. 谢谢你的帮助。

UPDATE: 更新:

I think the only way to have Api Management wait is use of a logic app. 我认为等待Api Management的唯一方法是使用逻辑应用程序。 Not sure about this. 对此不确定。

Any Azure experts out there? 有任何Azure专家吗?

The way APIM is behaving is actually expected. 实际上预期APIM的行为方式。

Service Bus is meant to decouple different (micro)services and inherently doesn't have a request-response style of operation though it can be implemented that way. 服务总线旨在解耦不同的(微)服务,尽管可以通过这种方式实现,但它固有地不具有请求-响应样式的操作。

Here is one way to can design/implement you system 这是一种可以设计/实现系统的方法

  • First, for a request-response style operation with Service Bus, one way you can achieve it is by using two queues . 首先,对于使用Service Bus进行请求-响应样式的操作,可以通过使用两个队列来实现。

    One for sending the request (along with some Unique ID - GUID will do) and the other for receiving the response (which again contains the Unique ID sent in the request). 一个用于发送请求(连同一些唯一ID-GUID一起使用),另一个用于接收响应(再次包含请求中发送的唯一ID)。

  • Instead of having APIM work with Service Bus, call a Logic App or Function which does this for you. 不用让APIM与Service Bus一起工作,而是调用为您执行此操作的Logic App或Function。

  • Finally, waiting for the response is something that will depend on your use case. 最后,等待响应取决于您的用例。

    If you have a very long running task, its best to follow the Async Pattern implemented by both Logic Apps and Functions ( using Durable Functions ), which return a 202 Accepted response immediately with a status URI that your client can poll for updates. 如果您的任务运行时间很长,则最好遵循由Logic应用程序和函数( 使用持久函数 )实现的异步模式,后者会立即返回202 Accepted响应以及状态URI,您的客户端可以轮询该更新以进行更新。

    But if its a quick response (before the HTTP request times out), you could probably wait for the response service bus message and return the response then. 但是,如果响应迅速(在HTTP请求超时之前),则您可以等待响应服务总线消息,然后返回响应。 For this, your Logic App or Function would have to poll/wait for the service bus message with the same unique ID and then return the response. 为此,您的Logic App或Function必须轮询/等待具有相同唯一ID的服务总线消息,然后返回响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM