Note that there are some explanatory texts on larger screens.

plurals
  1. POGrails Atmosphere Plugin broadcast to different clients
    text
    copied!<p>I'm trying to extend the Groovy Mag Atmosphere Example (<a href="https://github.com/rbramley/GroovyMagJMS" rel="nofollow noreferrer">https://github.com/rbramley/GroovyMagJMS</a>) to broadcast to different clients. (Like in <a href="https://stackoverflow.com/questions/7199164/broadcasting-to-a-subset-of-subscribers-in-atmosphere">Broadcasting to a subset of subscribers in Atmosphere</a>)</p> <p>A client connects with url <a href="http://localhost:8080/GrailsTest/atmosphere/messages/?id=1" rel="nofollow noreferrer">http://localhost:8080/GrailsTest/atmosphere/messages/?id=1</a>. An id will be passed to the server. The new added lookupBroadcaster Method creates a new Broadcaster Object with the id. When I wanna broadcast a message, the client does not receive the result.</p> <p>Can somebody help me and maybe try it out?</p> <p>I'm added the atmosphere 0.8.2 library to BuildConfig.groovy to use mappings like '/atmosphere/messages/*'.</p> <pre><code>dependencies { runtime 'org.atmosphere:atmosphere-runtime:0.8.2' } class AtmosphereService { static transactional = false static atmosphere = [mapping: '/atmosphere/messages/*'] static exposes = ['jms'] @Subscriber(topic='msgevent') def onEvent(msg) { println 'onevent' def payload = msg if(msg instanceof Map) { // convert map messages to JSON payload = msg.encodeAsJSON() } Broadcaster b = lookupBroadcaster(msg["id"], false); b.broadcast(payload) return null } Broadcaster lookupBroadcaster(String id, Boolean createBroadcast) { return BroadcasterFactory.getDefault().lookup(id, createBroadcast) } def onRequest = { event -&gt; def req = event.request def id = req.getParameter("id") Broadcaster b = lookupBroadcaster(id, true); event.setBroadcaster(b); b.addAtmosphereResource(event) event.suspend() } def onStateChange = { event -&gt; if (event.message) { log.info "onStateChange, message: ${event.message}" if (event.isSuspended()) { event.resource.response.writer.with { write "&lt;script&gt;parent.callback('${event.message}');&lt;/script&gt;" flush() } event.resume() } } } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload