我正在尝试制作一个 webapp,并且我想在刷新 web 时发送一条消息(这是我制作的一个简单示例,因为它更容易理解)。我尝试过使用内部渠道,但我也尝试过使用 Kafka,但也没有用。
失败消息是“未找到频道“通知刷新”的订阅者”。当我用 kafka 尝试它时没有错误,但它没有检索到消息。
我的资源:它返回发布者是因为主应用程序具有的功能而不是这个可重现的示例,但这不是问题。
@ApplicationScoped
@Path("/refresh")
public class refresh {
@Inject
@Channel("notify-refresh")
Emitter<String> emitter;
@Inject
@Channel("uploaded")
Publisher<String> publisher;
@GET
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType(MediaType.TEXT_PLAIN)
public Publisher<String> hello() {
emitter.send("lets go");
return publisher;
}
}
然后这个类接受消息,进行一些更改并发送到处理器:
@ApplicationScoped
public class generator {
@Incoming("notify-refresh")
@Outgoing("send-processor")
public String sendToProcessor(String uni){
return uni;
}
}
返回资源的处理器:
@ApplicationScoped
public class processor {
@Incoming("send-processor")
@Outgoing("uploaded")
public String processMsg(String uni){
return uni;
}
}