I am new to CometD. Is there a simple example for implementing a service channel model in the case of a response / request model. I saw cometd.org, but there is no example how to send an answer if I publish to any channel.
This is the client side.
alert("channel published1"); dojox.cometd.publish('/service/getlist'); alert("channel published"); dojox.cometd.subscribe('/service/getlist', function(message) { alert(message); });
this is the server side "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<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(); }
}
source share