【发布时间】:2019-01-05 16:24:43
【问题描述】:
我是 CometD 的新手。我用 Java 编写了一个基本的 CometD 服务器和一个简单的 CometD 客户端。我收到邮递员对 /meta/handshake、/meta/connect、/meta/subscribe 频道的成功响应。但是当我开始使用我的 cometD java 客户端(我从 https://protect-us.mimecast.com/s/vLH6CNk58of1Ow1GsmVz4u?domain=github.com 重用)时,握手失败并显示以下消息。
失败 {supportedConnectionTypes=[long-polling], 通道=/元/握手,id=22,版本=1.0}
我在我的代码中使用 cometdVersion - '4.0.0',jettyVersion - '9.4.0.v20161208', springbootVersion - '1.5.14.RELEASE'。
我已经对 AnnotationCometDServlet 进行了动态 servlet 注册,并添加了 /notifications 作为映射。
我在bayeuxServer 配置类中创建了如下频道。
bayeuxServerImpl.createChannelIfAbsent("/updates",
(ServerChannel.Initializer) channel -> channel.addAuthorizer(GrantAuthorizer.GRANT_ALL));
在客户端代码中,我使用 /notifications 作为默认 URL,通道作为 /updates
@Service("cometListener")
@Slf4j
public class BayeuxListener implements BayeuxServer.SessionListener {
@Inject
private BayeuxServer bayeuxServer;
@Session
private ServerSession serverSession;
@Configure({"/updates**,/notifications**"})
protected void configureChannel(ConfigurableServerChannel channel) {
channel.addAuthorizer(GrantAuthorizer.GRANT_ALL);
channel.addAuthorizer(GrantAuthorizer.GRANT_PUBLISH);
channel.setPersistent(true);
}
@Listener("/meta/*")
public void monitorMeta(ServerSession session, ServerMessage message) {
log.info("monitoring meta"+message.toString()+"channel "+message.getChannel()+"session id "+session.getId());
}
@Listener("/meta/subscribe")
public void monitorSubscribe(ServerSession session, ServerMessage message) {
log.info("Monitored Subscribe from " + session + " for " + message.get(Message.SUBSCRIPTION_FIELD));
}
@Listener("/meta/unsubscribe")
public void monitorUnsubscribe(ServerSession session, ServerMessage message) {
log.info("Monitored Unsubscribe from " + session + " for " + message.get(Message.SUBSCRIPTION_FIELD));
}
@Listener("/updates")
public void handlesrgUpdates(ServerSession client, ServerMessage message) {
ServerSession cilentSession = bayeuxServer.getSession(client.getId());
client.deliver(cilentSession,"/updates", "Received message back from client");
}
}
【问题讨论】:
标签: java spring-boot cometd