blazeds push message to all clients
I have a bootstrapper that handles sessionDestroyed
, sessionCreated
, ClientCreated
, ClientDestroyed
, MessageClientDestroyed
, MessageClient开发者_运维知识库Created
events.
My aim is to send a disconnect message to all clients or all subscribed destinations.
So i need a push mechanism inside the service. I have tried to get messageService and MessageBroker
but i got exception.
I have tried messageBroker.routeMessageToService(msg,null)
;
and messageService.pushMessageToClients(msg,true)
; both is unsuccessful because i could not get messageService and messageBroker.
How can i get MessageBroker
or MessageService
in service clientDestroyed event.
String clientId = UUIDUtils.createUUID();
MessageBroker msgBroker = MessageBroker.getMessageBroker(null);
JOptionPane.showMessageDialog(null, msgBroker);
AsyncMessage msg = new AsyncMessage();
msg.setDestination(dest.destinationList.get(i));
msg.setClientId(clientId);
msg.setMessageId(UUIDUtils.createUUID());
msg.setHeader("disconnected",0);
msg.setBody(client.getId());
msgBroker.routeMessageToService(msg, null);
this is my working code hope it helps to somebody.
精彩评论