Loading...

Set up an API within Azure API Management to facilitate the implementation of server-sent events.

Set up an API within Azure API Management to facilitate the implementation of server-sent events.

Server-Sent Events (SSE) is a web technology designed to enable servers to transmit data to clients without the need for client-initiated requests. SSE proves to be highly advantageous for applications requiring real-time updates, such as chat platforms, news feeds, or stock price trackers. Traditionally, these applications would involve clients repeatedly requesting data from servers at predefined intervals.

 

This blog post delves into the configuration process of setting up a server-sent events (SSE) API within Azure API Management (APIM). APIM is a comprehensive service offering the creation, publication, management, and security of APIs. APIM facilitates SSE APIs by applying a specialized policy that enables the seamless transmission of streaming responses.

 

Step-by-Step Guide: Configuring a Sample SSE API in Azure API Management

 

To configure a sample SSE API in APIM, adhere to the following instructions:

 

  • Let's consider the following publicly accessible SSE API provided by Postman as an illustrative example:

   postman-echo.com/server-events/:numberOfEvents

 

anjalidivitha_0-1683869074960.png

 

  • Import this SSE API as a HTTP API into APIM, depending on your specific requirements,

anjalidivitha_1-1683869074994.png

 

  • Create a GET operation that includes a query parameter named 'eventscount' to specify the desired number of events to generate,

anjalidivitha_2-1683869075006.png

 

 

  • Navigate to the Inbound processing tab and incorporate the "Stream response content" policy as demonstrated below. 

anjalidivitha_3-1683869075029.png

 

<policies> <inbound> <base /> </inbound> <backend> <forward-request timeout="60" buffer-response="false" fail-on-error-status-code="true" /> </backend> <outbound> <base /> </outbound> <on-error> <base /> </on-error> </policies>

 

  • Save the policy and proceed to test the SSE API within APIM.

Testing:

 

  • Fetch the Request URL of the API endpoint from Azure Portal:

anjalidivitha_4-1683869075043.png

 

  • Utilize Postman or any other SSE-compatible tool to send a GET request to the APIM endpoint, including the query parameter ‘eventscount’ with a value of, for example, 10.

anjalidivitha_5-1683869075054.png

 

  • You should observe the streaming of 10 events with data being transmitted from the server and we can confirm that the APIM endpoint successfully streams the events retrieved from the backend server.

Potential causes for the SSE API not functioning as anticipated in APIM may include:

 

When utilizing APIM to access a backend API implementing SSE, it is essential to follow these guidelines for verification:

 

  • To prevent issues with SSE APIs in APIM, it is recommended to disable request/response body logging for Azure Monitor and Application Insights. These services offer application performance monitoring features, allowing the logging of request/response bodies at various stages of request execution. However, for SSE APIs, logging can cause unexpected buffering and potential problems. Azure Monitor and Application Insights diagnostic settings configured at the global/All APIs scope apply to all APIs within the service, but you can override these settings for individual APIs as needed. Disabling request/response body logging ensures improved performance and reliability of SSE APIs by avoiding unnecessary data collection.

anjalidivitha_6-1683869075057.png

  • SSE requires a persistent HTTP connection, which is supported by the dedicated API Management tiers (Premium, Standard, Basic, and Developer). However, the Consumption tier does not support persistent connections. Consider selecting a suitable service tier that supports SSE based on your requirements.
  • To prevent idle connections from timing out, it is recommended to use methods that keep them active. For example, you can set up a TCP keepalive signal on the backend side of the connection or ensure that the client sends data at least every 4 minutes.
  • To ensure clients receive events as soon as they occur, disable response buffering in the forward-request policy. This can be achieved by setting the buffer-response attribute to false, as demonstrated below:

 

<forward-request timeout="120" fail-on-error-status-code="true" buffer-response="false"/>

 

  • Avoid using policies that introduce delays in responses. Certain policies like validate-content can hold up response content, which is not suitable for SSE APIs.
  • Make sure to disable response caching to ensure that clients receive timely notifications.
  • Before launching your API, thoroughly test its performance under stress. Utilize common methods to simulate heavy load and identify any speed or stability issues.

I hope you find these guidelines helpful and informative. If you have any questions or feedback, please feel free to leave a comment below :)

 

Reference: https://learn.microsoft.com/en-us/azure/api-management/how-to-server-sent-events

 

Published on:

Learn more
Azure PaaS Blog articles
Azure PaaS Blog articles

Azure PaaS Blog articles

Share post:

Related posts

Transforming Field Operations with AI, Azure Maps & Dynamics 365

Efficient field operations are the backbone of successful, data-driven organizations. Yet, many businesses continue to struggle with scattered...

13 hours ago

Failures Happen in Cloud, but how Azure Cosmos DB keeps your Applications Online

The only thing that’s constant in distributed systems is failures. No cloud platform is immune to failures — from regional outages and transie...

1 day ago

The `azd` extension to configure GitHub Copilot coding agent integration with Azure

This post shares how to set up the GitHub Copilot coding agent integration with Azure resources and services by using the Azure Developer CLI ...

2 days ago

Announcing Azure MCP Server 1.0.0 Stable Release – A New Era for Agentic Workflows

Today marks a major milestone for agentic development on Azure: the stable release of the Azure MCP Server 1.0! The post Announcing Azure MCP ...

4 days ago

From Backup to Discovery: Veeam’s Search Engine Powered by Azure Cosmos DB

This article was co-authored by Zack Rossman, Staff Software Engineer, Veeam; Ashlie Martinez, Staff Software Engineer, Veeam; and James Nguye...

4 days ago

Azure SDK Release (October 2025)

Azure SDK releases every month. In this post, you'll find this month's highlights and release notes. The post Azure SDK Release (October 2025)...

5 days ago

Microsoft Copilot (Microsoft 365): [Copilot Extensibility] No-Code Publishing for Azure AI Foundry Agents to Microsoft 365 Copilot Agent Store

Developers can now publish Azure AI Foundry Agents directly to the Microsoft 365 Copilot Agent Store with a simplified, no-code experience. Pr...

5 days ago

Azure Marketplace and AppSource: A Unified AI Apps and Agents Marketplace

The Microsoft AI Apps and Agents Marketplace is set to transform how businesses discover, purchase, and deploy AI-powered solutions. This new ...

8 days ago

Episode 413 – Simplifying Azure Files with a new file share-centric management model

Welcome to Episode 413 of the Microsoft Cloud IT Pro Podcast. Microsoft has introduced a new file share-centric management model for Azure Fil...

9 days ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy