Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Availability
Important
This feature is available in the Premium, Standard, Basic, and Developer tiers of API Management.
This article describes how to send messages from API Management to Azure Service Bus by using policy-based integration. Use API Management to provide a secure and scalable way to send messages to Service Bus.
Azure Service Bus is a fully managed enterprise messaging service designed to decouple applications and services, enabling reliable cloud messaging between distributed systems. It supports AMQP (Advanced Message Queuing Protocol) for systems to send messages to message queues for one-to-one communication and topics for publish/subscribe patterns. Service Bus is ideal for scenarios requiring asynchronous operations, load leveling, or integration across hybrid cloud environments. For more information, see the Azure Service Bus documentation.
With policy-based integration, API Management provides:
- Secure REST-based messaging for external clients - External systems and mobile apps that lack native AMQP support can send messages to Service Bus by using standard HTTP/REST APIs via API Management. This approach simplifies integration and enhances security by eliminating the need for custom intermediaries.
- Governed third-party integrations - Enterprises can expose Service Bus endpoints through API Management with built-in managed identity authentication, enabling secure and observable messaging patterns for partners and third-party applications.
- Fire and forget model - No other backend services are required to send messages to Service Bus, allowing for simpler architectures and reduced operational overhead.
Note
- Integration of API Management with Service Bus is currently in preview.
- Only sending messages to Service Bus is supported.
Prerequisites
An API Management service instance. If you don't have one, see Create an API Management service instance.
An API Management API used to send messages to Service Bus.
A queue or topic in an Azure Service Bus namespace to receive messages. For detailed steps, see one of the following:
Note
- If you want to use topics and subscriptions, choose the Service Bus Standard or Premium tier.
- The Service Bus resource can be in a different subscription or even a different tenant than the API Management resource.
Permissions to assign roles to a managed identity.
Configure access to the service bus
To send messages to the service bus, you need to configure a managed identity for your API Management instance:
Enable a system-assigned or user-assigned managed identity for API Management in your API Management instance.
- If you enable a user-assigned managed identity, take note of the identity's Client ID.
Assign the identity the Azure Service Bus Data Sender role, scoped to the service bus. To assign the role, use the Azure portal or other Azure tools.
Configure send-service-bus-message policy
Configure the send-service-bus-message policy to send messages to the desired queue or topic.
For example, use the send-service-bus-message policy in the inbound policy section to send the request body of an API request when the gateway receives it:
In the Azure portal, go to your API Management instance.
In the left-hand menu, select APIs, then select the API where you want to add the policy.
Select All operations.
At the top of the screen, select the Design tab.
In the Inbound processing or Outbound processing window, select the
</>(code editor) icon. For more information, see How to set or edit policies.Position your cursor in the
inboundoroutboundpolicy section.Add the
send-service-bus-messagepolicy to the policy configuration, then configure the attributes and elements as needed.For example, send the request body as a message:
<send-service-bus-message queue-name="my-queue"> <payload>@(context.Request.Body.As<string>())</payload> </send-service-bus-message>You can use any expression that returns a string as the value for the
payloadelement.Select Save to save the updated policy configuration. As soon as you save it, the policy is active and messages are sent to the designated service bus.