我是CometD的新手,在响应/请求模型的情况下,是否有任何简单的示例来实现服务信道模型.我见过cometd.org但是如果我发布到任何频道,就没有这样的例子来回复发送回复.
这是客户端
alert("channel published1");
dojox.cometd.publish('/service/getlist');
alert("channel published");
dojox.cometd.subscribe('/service/getlist', function(message) {
alert(message);
});
这是服务器端“ConfigurationServlet”
bayeux.createIfAbsent("/service/getlist", new ConfigurableServerChannel.Initializer() {
//new EchoService(bayeux);
@Override
public void configureChannel(ConfigurableServerChannel channel) {
/*channel.setPersistent(true);
GetListChannelListener channelListner = new GetOrderListChannelListener();
channel.addListener(channelListner);*/
new EchoService(bayeux);
}
});
EchoService的
public class EchoService extends AbstractService{
public EchoService(BayeuxServer bayeuxServer)
{
super(bayeuxServer, "getlist");
addService("/service/getlist", "processEcho");
}
public void processEcho(ServerSession remote,Map data)
{
try{
System.out.println("Start Process Echo");
getBayeux().getChannel("/service/getlist").publish(getServerSession(), "Hello", null);
System.out.println("End Process Echo");
}catch(Exception exp){
exp.printStackTrace();
}
//remote.deliver(getServerSession(), "/service/getlist", data, null);
}
}