【问题标题】:How to implement SSE in Mule 3.9.0 using http listener and jersey如何使用 http listener 和 jersey 在 Mule 3.9.0 中实现 SSE
【发布时间】:2021-12-29 22:43:26
【问题描述】:

是否可以使用 mule (3.9.0) 和 jersey 实现服务器发送事件 (SSE)?似乎mule http监听器立即关闭了连接。有没有办法让骡子保持插座打开?

我已经实现了配置:

<http:listener-config name="HttpListenerConfig" host="0.0.0.0" basePath="/myservice" port="8090" />

<flow name="NotificationServiceFlow">
        <http:listener config-ref="HttpListenerConfig" path="/sse/*" allowedMethods="GET" parseRequest="false" responseStreamingMode="ALWAYS">
        </http:listener>
        <jersey:resources>
            <component>
                <spring-object bean="NotificationResource"/>
            </component>
        </jersey:resources>
    </flow>

以及球衣资源如下:

@Path("/notifications")
public class NotificationResource {
    
    private SseBroadcaster broadcaster = new SseBroadcaster();
    
    @GET
    @Produces(SseFeature.SERVER_SENT_EVENTS)
    public EventOutput subscribe() {
        final EventOutput eventOutput = new EventOutput();
        broadcaster.add(eventOutput);
        return eventOutput;
    }
    
    public void broadcast(String json) {
        OutboundEvent.Builder builder = new OutboundEvent.Builder();
        OutboundEvent event = builder
            .mediaType(MediaType.APPLICATION_JSON_TYPE)
            .data(String.class, json)
            .build();
        broadcaster.broadcast(event);
    }
}

【问题讨论】:

  • 如果mule 3.9.0无法实现,可以用mule 4实现吗?

标签: jersey mule server-sent-events httplistener


【解决方案1】:

据我所知,任何版本的 Mule 都不支持服务器端事件。

另一种方法是使用 Mule 4 Websockets 连接器:https://docs.mulesoft.com/websockets-connector/1.0/

在任何情况下,使用 Mule 3.9.0 都是不安全的。建议迁移到最新版本的 Mule 4。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-08
    • 2014-08-14
    • 2012-10-24
    相关资源
    最近更新 更多