Search code examples
grailsatmosphere

websocket connection not happening using grails event-push plugin


I am trying to integrate grails events-push plugin to push events to browser however its not working. I made below changes for it

BuildConfig.groovy

 grails.tomcat.nio = true
 compile ":events-push:1.0.M7"

Config.groovy

events.push.servlet.initParams = [
        'org.atmosphere.cpr.cometSupport': 'org.atmosphere.container.Tomcat7CometSupport',
        "org.atmosphere.cpr.CometSupport.maxInactiveActivity": "100000"
 ]

  tomcat.nio=true

Deleted context.xml(generated by plugin) from META-INF folder as tomcat was not working with it

In Client side i.e angular js

window.grailsEvents = new grails.Events('http://localhost:8080');

I managed to start my application successfully. I also below message in log

DEBUG cpr.DefaultBroadcaster  - Broadcaster eventsbus doesn't have any associated resource. Message will be cached in the configured BroadcasterCache

Bu when I open my application in browser websocket do not work. In serve end I see below meesage

2014-05-01 15:19:56,365 [http-nio-8080-exec-3] DEBUG cpr.AsynchronousProcessor  - Timing out the connection for request AtmosphereRequest{ contextPath= servletPath=/g-eventsbus pathInfo=/eventsbus requestURI=/g-eventsbus/eventsbus requestURL=http://localhost:8080/g-eventsbus/eventsbus destroyable=false}
2014-05-01 15:19:56,366 [http-nio-8080-exec-3] WARN  websocket.DefaultWebSocketProcessor  - Unable to retrieve AtmosphereResource for org.apache.catalina.websocket.WsOutbound@269dd750
2014-05-01 15:19:57,783 [http-nio-8080-exec-5] DEBUG cpr.AsynchronousProcessor  - Timing out the connection for request AtmosphereRequest{ contextPath= servletPath=/g-eventsbus pathInfo=/eventsbus requestURI=/g-eventsbus/eventsbus requestURL=http://localhost:8080/g-eventsbus/eventsbus destroyable=false}

I browser console end I see

WebSocket connection to 'ws://localhost:8080/g-eventsbus/eventsbus?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=1.1.0.beta3&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=0&topics=eventsbus' failed: WebSocket is closed before the connection is established. 

Guys please help me I am struggling with this plugin from long time.


Solution

  • Thanks mpccolorado for you reply. I got it working actually issue was in JS grails.Events should be created with globalTopicName.

    var grailsEvents = new grails.Events(GRAILS_EVENT_URL, {globalTopicName: 'newReview'});