【发布时间】: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