【发布时间】:2014-02-11 05:07:36
【问题描述】:
关于进一步分析的帖子的详细说明 Cometd javascript client doesn't subscribe to broadcast channel.
如果 Cometd-Spring 程序开始广播新消息,并且 cometd javascript 客户端稍后订阅,则客户端无法接收新广播消息。但是cometd服务器重启后客户端开始接收广播消息。
广播频道:/notification
客户代码:
function _metaHandshake(handshake)
{
if (handshake.successful === true)
{
cometd.batch(function(){
cometd.subscribe('/notification', function(message){
console.log("Received Data ::"+JSON.stringify(message.data));
});
});
}
}
服务器代码:
@javax.inject.Named
@javax.inject.Singleton
@Service("notificationService")
public class NotificationService {
@Inject
private BayeuxServer bayeuxServer;
@Session
private LocalSession session;
@Configure("/notification")
public void configureServiceChannel(ConfigurableServerChannel channel)
{
channel.setPersistent(true);// channel persistent
channel.addAuthorizer(GrantAuthorizer.GRANT_ALL);
}
public void onExternalEvent( Map<String, Object> data)
{
this.bayeuxServer.getChannel("/notification").publish(this.session, data);
}
}
【问题讨论】:
标签: javascript spring cometd