Search code examples
pushblazeds

blazeds push message to all clients


I have a bootstrapper that handles sessionDestroyed, sessionCreated, ClientCreated, ClientDestroyed, MessageClientDestroyed, MessageClientCreated 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.


Solution

  •              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.