Hi
I'm working with the sample application
'grizzly-cometd-bayeux'(/samples/comet/cometd-javaapiupdate-chat). I use
'grizzly-cometd-webserver-1.9.18-SNAPSHOT.jar' to deploy the war.
I subscribed to multiple channels in the file chat.js. But the messages are
getting published ONLY to the LAST subscribed channel and NOT to the others.
Please find my code changes below.
_______________________________________________________________________
chat.js : I modified the function room.join(). Added the 3 lines to
subscribe.
join: function(name){
if(name == null || name.length==0 ){
alert('Please enter a username!');
}else{
dojox.cometd.init(new
String(document.location).replace(/http:\/\/[^\/]*/,'').replace(/\/\/.*$/,'\/cometd')+"/cometd");
this._username=name;
dojo.byId('join').className='hidden';
dojo.byId('joined').className='';
dojo.byId('phrase').focus();
// Really need to batch to avoid ordering issues
dojox.cometd.startBatch();
dojox.cometd.subscribe("/chat/demo", room, "_chat");
//Change start
dojox.cometd.subscribe("/chat/demo1", room, "_chat");
dojox.cometd.subscribe("/chat/demo2", room, "_chat");
dojox.cometd.subscribe("/chat/demo3", room, "_chat");
//Change End
dojox.cometd.publish("/chat/demo", { user: room._username, join:
true, chat : room._username+" has joined"});
dojox.cometd.endBatch();
}
}
____________________________________________
com.sun.grizzly.bayeux.BayeuxExternalServlet.init() : Publishes to all
subscribed channels.
timer.scheduleAtFixedRate(new Runnable() {
public void run() {
CometEngine engine = CometEngine.getEngine();
String channels[] = { "/chat/demo", "/chat/demo1", "/chat/demo2",
"/chat/demo3" };
for (int i = 0; i < channels.length; i++) {
String topic = channels[i];
CometContext context = engine.getCometContext(topic);
if (context != null) {
System.out.println("wake up call for " + topic);
Map<String, Object> map = new HashMap<String, Object>();
map.put("chat", "Wake up call from the chatroom :-) to "+topic);
map.put("user", "ChatPigner");
Data data = new Data();
data.setMapData(map);
data.setChannel(topic);
DeliverResponse deliverResponse = new DeliverResponse();
deliverResponse.setChannel(topic);
// deliverResponse.setClientId("");
deliverResponse.setData(data);
deliverResponse.setLast(true);
deliverResponse.setFollow(true);
deliverResponse.setFinished(true);
try {
context.notify(deliverResponse);
} catch (IOException ex) {
ex.printStackTrace();
}
;
}
}
}
}, 10, 3, TimeUnit.SECONDS);
when I debugged, the CometContext.handlers() is Empty for all the channels
except for the /chat/demo3, which is the LAST subscribed one.
BUT if I send a message from the webpage, its is published properly
irrespective of the channel.
Is my approach wrong or is there a bug in the code?
Let me know if anything else is required.
Screenshot of the app:
http://www.nabble.com/file/p24460710/Clipboard01.jpg
Clipboard01.jpg
Thanks
Abey Tom
--
View this message in context: http://www.nabble.com/grizzly-cometd-bayeux-not-sending-messages-to-all-subscribed-clients.-tp24460710p24460710.html
Sent from the Grizzly - Users mailing list archive at Nabble.com.