Implementing Server Sent Events with Mule 4.4.0

162 Views Asked by At

I am trying to implement Server Sent Events using the HTTP connector in Mule 4.4.0. I have a flow with an HTTP Listener that is accepting SSE client connections and responding to the SSE heartbeat:

<flow name="SSE_Subscribe_Flow">
        <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/events/subscribe" allowedMethods="GET" responseStreamingMode="ALWAYS">
            <http:response statusCode="200" >
                <http:headers><![CDATA[#[output application/java
---
{
    "Content-Type" : "text/event-stream",
    "Cache-Control" : "no-cache",
    "Connection" : "keep-alive"
}]]]>
                </http:headers>
            </http:response>
        </http:listener>
        <logger level="INFO" message="#[message]"/>
    </flow>

Is it possible to push messages to the open connection from other flows?

2

There are 2 best solutions below

0
On

Mule currently doesn't support Server-Sent Events. As an alternative, if you can use Websockets instead note that Mule 4 has a Websockets connector.

0
On

It might be possible to create a custom connector for SSE, but I agree with aled, it's not possible with the built in HTTP connector.