سؤال

I've used the sample to check how atmosphere works and a little modified it: add a service to send messages:

def sendMessage(String message){
        String mapping = "/jabber/chat/12345"
        Broadcaster b = BroadcasterFactory.getDefault().lookup(DefaultBroadcaster.class, mapping)
        println("Broadcast resources size:" +b.getAtmosphereResources().size())
        def resp = [type: "chat", resource: mapping, message: message] as JSON
        b.broadcast(resp)
    }

But looks like when I call the function some times AtmosphereResource for my connection in broadcaster is missed and client didn't recieve a message. Does anyone know what the problem is? Thanks for help.

هل كانت مفيدة؟

المحلول 2

After some debugging switched to SimpleBroadcaster implementation and now code works pretty fine:
Handler class

@Override
    void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String mapping = "/jabber/chat" + request.getPathInfo()
        Broadcaster b = BroadcasterFactory.getDefault().lookup(SimpleBroadcaster.class, mapping, true)
        Meteor m = Meteor.build(request)
        m.setBroadcaster(b)
    }

Service

def sendMessage(String message){
        String mapping = "/jabber/chat/12345"
        Broadcaster b = BroadcasterFactory.getDefault().lookup(mapping)
        println("Broadcast resources size:" +b.getAtmosphereResources().size())
        def resp = [type: "chat", resource: mapping, message: message] as JSON
        b.broadcast(resp)
    }

نصائح أخرى

First of all what transport protocol you are using ?

If it is 'long-polling'(default) or 'polling' atmosphere try to reconnect after 5 minutes(default) if no message (or event) are sent or received.

Maybe one of reconnections is field ?

I have some similar issue system was reconnecting only 5 times. So after 5x5minutes no connection was between client and server. Check browser log/established connections to see do your browser have valid connection to server. Also try to play with atmosphere props (reduce value of timeout conf to 10000 and try to reproduce problem.)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top