Events Push - PushEvents.groovy & namespace issue

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Events Push - PushEvents.groovy & namespace issue

tacrom

Hey,

as I mentioned earlier, I’m back with a question relating the Events Push Plugin

(I’m running events-push-1.0.M7 with platform-core-1.0.RC5).

 

I’ve got the following code in my PushService class:

<code>

    @Listener(namespace = 'browser')

    def savedTodo(Map data) {

        println(data)

        data.moreData = 'There we go ...'

        event('savedTodo', data, {}) // will trigger registered browser on 'savedTodo' topic

    }

</code>

 

And the following entry in my PushEvents.groovy file:

<code>

events = {

  “savedTodo” browser: true

}

</code>

 

So far, so good. Everything works well. Now I wanted to play around with namespaces and

I tried the following: I added a new method to PushService:

<code>

@Listener(namespace = 'secure')

    def holadaridio(Map data) {

        println('in holadaridio')

        data.name = 'heast!'

        event('holadaridio', data, {})

    }

</code>

 

And I invoke both methods from a controller on a button click:

<code>

class TestController {

  def pushService

 

  def testIt = {

    def data = [:]

    data.name = ‘Mister Controller’

    pushService.savedTodo(data)

    pushService.holadaridio(data)

    render(view: ‘/index’)

  }

}

</code>

 

And now, both methods communicate with the frontend JavaScript,

although I’ve just registered for the ‘savedTodo’ method within ‘grailsEvents.on()’

method …., but, so far everything still ‘works’ the one or the other way…

 

I now wanted to restrict the access for the methods and therefore added a

‘namespace’ declaration for the ‘savedTodo’ and ‘holadaridio’ events in

PushEvents.groovy:

<code>

events = {

    "savedTodo" namespace: 'browser', browser:true // allows browser push on this topic

    "holadaridio" namespace: 'secure', browser: false

}

</code>

 

Aaaaaaaaand: nothing. The methods are called (as I see on debugging the code), and they also

return the correct result (no Errors or Exceptions are thrown), but the frontend doesn’t receive

anything… if I remove the ‘namespace’ declaration the frontend receives the data…

 

What am I doing wrong? Am I doing something wrong?

 

Thanks for your answers/advices in advance – I really appreciate it a lot! ;)

Reply | Threaded
Open this post in threaded view
|

Re: Events Push - PushEvents.groovy & namespace issue

smaldini
There are some things there:

1/
events = {
  someTopic browser:false  //Only prevent subscription from browser on that topic, which is the default, you only have to define the opposite in fact browser:true
}

2/
It doesnt make sense to call the pushService methods if they are @Listener, just use this in your controller:
event for:'secure', topic:'holadaridio'
@Listener doesn't transform the call you make to the service, it may someday but not atm.

3/
"savedTodo" namespace: 'browser' 
This line means you're selecting this topic on this namespace to apply some default mech (fork, onReply, filter etc) for whenever you use event for:'browser', topic:'savedTodo' in Grails artifacts.
It also acts as a whitelist inbound in the events push case (the specific events bus extension you use there). You have to do this whenever you want grailsEvents.send('savedTodo')  in Javascript.


On Thu, Feb 14, 2013 at 3:13 PM, Heinz Romirer | TAC GmbH <[hidden email]> wrote:

Hey,

as I mentioned earlier, I’m back with a question relating the Events Push Plugin

(I’m running events-push-1.0.M7 with platform-core-1.0.RC5).

 

I’ve got the following code in my PushService class:

<code>

    @Listener(namespace = 'browser')

    def savedTodo(Map data) {

        println(data)

        data.moreData = 'There we go ...'

        event('savedTodo', data, {}) // will trigger registered browser on 'savedTodo' topic

    }

</code>

 

And the following entry in my PushEvents.groovy file:

<code>

events = {

  “savedTodo” browser: true

}

</code>

 

So far, so good. Everything works well. Now I wanted to play around with namespaces and

I tried the following: I added a new method to PushService:

<code>

@Listener(namespace = 'secure')

    def holadaridio(Map data) {

        println('in holadaridio')

        data.name = 'heast!'

        event('holadaridio', data, {})

    }

</code>

 

And I invoke both methods from a controller on a button click:

<code>

class TestController {

  def pushService

 

  def testIt = {

    def data = [:]

    data.name = ‘Mister Controller’

    pushService.savedTodo(data)

    pushService.holadaridio(data)

    render(view: ‘/index’)

  }

}

</code>

 

And now, both methods communicate with the frontend JavaScript,

although I’ve just registered for the ‘savedTodo’ method within ‘grailsEvents.on()’

method …., but, so far everything still ‘works’ the one or the other way…

 

I now wanted to restrict the access for the methods and therefore added a

‘namespace’ declaration for the ‘savedTodo’ and ‘holadaridio’ events in

PushEvents.groovy:

<code>

events = {

    "savedTodo" namespace: 'browser', browser:true // allows browser push on this topic

    "holadaridio" namespace: 'secure', browser: false

}

</code>

 

Aaaaaaaaand: nothing. The methods are called (as I see on debugging the code), and they also

return the correct result (no Errors or Exceptions are thrown), but the frontend doesn’t receive

anything… if I remove the ‘namespace’ declaration the frontend receives the data…

 

What am I doing wrong? Am I doing something wrong?

 

Thanks for your answers/advices in advance – I really appreciate it a lot! ;)




--
Stéphane
--

Reply | Threaded
Open this post in threaded view
|

RE: Events Push - PushEvents.groovy & namespace issue

tacrom

Ahhh, I  see –thanks, I’ll try it right now :)

 

From: Stephane Maldini [mailto:[hidden email]]
Sent: Thursday, February 14, 2013 4:28 PM
To: [hidden email]
Subject: Re: [grails-user] Events Push - PushEvents.groovy & namespace issue

 

There are some things there:

 

1/

events = {

  someTopic browser:false  //Only prevent subscription from browser on that topic, which is the default, you only have to define the opposite in fact browser:true

}

 

2/

It doesnt make sense to call the pushService methods if they are @Listener, just use this in your controller:

event for:'secure', topic:'holadaridio'

@Listener doesn't transform the call you make to the service, it may someday but not atm.

 

3/

"savedTodo" namespace: 'browser' 

This line means you're selecting this topic on this namespace to apply some default mech (fork, onReply, filter etc) for whenever you use event for:'browser', topic:'savedTodo' in Grails artifacts.

It also acts as a whitelist inbound in the events push case (the specific events bus extension you use there). You have to do this whenever you want grailsEvents.send('savedTodo')  in Javascript.

 

On Thu, Feb 14, 2013 at 3:13 PM, Heinz Romirer | TAC GmbH <[hidden email]> wrote:

Hey,

as I mentioned earlier, I’m back with a question relating the Events Push Plugin

(I’m running events-push-1.0.M7 with platform-core-1.0.RC5).

 

I’ve got the following code in my PushService class:

<code>

    @Listener(namespace = 'browser')

    def savedTodo(Map data) {

        println(data)

        data.moreData = 'There we go ...'

        event('savedTodo', data, {}) // will trigger registered browser on 'savedTodo' topic

    }

</code>

 

And the following entry in my PushEvents.groovy file:

<code>

events = {

  “savedTodo” browser: true

}

</code>

 

So far, so good. Everything works well. Now I wanted to play around with namespaces and

I tried the following: I added a new method to PushService:

<code>

@Listener(namespace = 'secure')

    def holadaridio(Map data) {

        println('in holadaridio')

        data.name = 'heast!'

        event('holadaridio', data, {})

    }

</code>

 

And I invoke both methods from a controller on a button click:

<code>

class TestController {

  def pushService

 

  def testIt = {

    def data = [:]

    data.name = ‘Mister Controller’

    pushService.savedTodo(data)

    pushService.holadaridio(data)

    render(view: ‘/index’)

  }

}

</code>

 

And now, both methods communicate with the frontend JavaScript,

although I’ve just registered for the ‘savedTodo’ method within ‘grailsEvents.on()’

method …., but, so far everything still ‘works’ the one or the other way…

 

I now wanted to restrict the access for the methods and therefore added a

‘namespace’ declaration for the ‘savedTodo’ and ‘holadaridio’ events in

PushEvents.groovy:

<code>

events = {

    "savedTodo" namespace: 'browser', browser:true // allows browser push on this topic

    "holadaridio" namespace: 'secure', browser: false

}

</code>

 

Aaaaaaaaand: nothing. The methods are called (as I see on debugging the code), and they also

return the correct result (no Errors or Exceptions are thrown), but the frontend doesn’t receive

anything… if I remove the ‘namespace’ declaration the frontend receives the data…

 

What am I doing wrong? Am I doing something wrong?

 

Thanks for your answers/advices in advance – I really appreciate it a lot! ;)



 

--

Stéphane

--