我是 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);
}
});
回声服务
public class EchoService extends AbstractService{
public EchoService(BayeuxServer bayeuxServer)
{
super(bayeuxServer, "getlist");
addService("/service/getlist", "processEcho");
}
public void processEcho(ServerSession remote,Map<String, Object> 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);
}
}