JackSojourn
JackSojourn

Reputation: 364

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. 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.

Is there a way to have the API Management wait for a reply?

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?

Thanks for any help.

UPDATE:

I think the only way to have Api Management wait is use of a logic app. Not sure about this.

Any Azure experts out there?

Upvotes: 0

Views: 1938

Answers (1)

PramodValavala
PramodValavala

Reputation: 6647

The way APIM is behaving is actually expected.

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.

    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).

  • Instead of having APIM work with Service Bus, call a Logic App or Function which does this for you.

  • 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.

    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. 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.

Upvotes: 2

Related Questions