서버에서 클라이언트로 메시지를 푸시하려고합니다. 나는 DOJO 1.7, Cometd 및 Jetty를 tomcat6과 통합하여 사용하고 있습니다.클라이언트 (도장)에 COMETD를 사용하는 서버 푸시
//Server side code
public class notificationService extends AbstractService {
public notificationService(BayeuxServer bayeux, String name) {
super(bayeux, name);
System.out.println("Inside constrcutor of Notification Service");
addService("/notification", "processNotification");
}
public void processNotification(ServerSession remote,ServerMessage.Mutable message)
{
System.out.println("Inside process Notification");
Map<String,Object> response = new HashMap<String,Object>();
response.put("payload",new java.util.Date());
getBayeux().createIfAbsent("/notification");
getBayeux().getChannel("/notification").publish(getServerSession(),response,null);
//remote.deliver(getServerSession(),"/notification", response, null);
}
//Client Side Code (DOJO)
var cometd = dojox.cometd;
cometd.init("http://serverip:port/cometd")
cometd.publish('/notification',{ mydata: { foo: 'bar' } });
cometd.subscribe('/notification', function(message)
{
//alert("Message received" + message.data.payload);
//alert(message.data.payload);
alert("Message received");
});
특정 채널을 구독하는 모든 클라이언트에게 메시지를 브로드 캐스트하려고합니다. remore.deliver를 사용하면 개별 클라이언트에 메시지를 보내지 만 해당 채널에 가입 한 모든 클라이언트에게는 메시지를 보내지 않습니다. channel.publish가 나를 위해 작동하지 않습니다 ... 어떤 도움이나 의견을 보내 주시면 감사하겠습니다.