Skip to content

Commit

Permalink
Documentation on events
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Mar 11, 2015
1 parent f4fde5f commit 715ae44
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/en/guide/async/events.gdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Grails 3.0 introduces a new Events API based on [Reactor|https://github.com/reactor/reactor].

All services and controllers in Grails 3.0 implement the [Events|api:grails.events.Events] trait.

The @Events@ trait allows the ability to consume and publish events that are handled by Reactor.

The default Reactor configuration utilises a thread pool backed event bus. You can however configure Reactor within @application.yml@, for example:

{code}
reactor
dispatchers:
default: myExecutor
myExecutor:
type: threadPoolExecutor
size: 5
backlog: 2048
{code}
11 changes: 11 additions & 0 deletions src/en/guide/async/events/consuming.gdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
There are several ways to consume an event. As mentioned previously services and controllers implement the [Events|api:grails.events.Events] trait.

The @Events@ trait provides several methods to register event consumers. For example:

{code}
on("myEvent") {
println "Event fired!"
}
{code}

Note that if you wish a class (other than a controller or service) to be an event consumer you simply have to implement the @Events@ trait and ensure the class is registered as a Spring bean.
8 changes: 8 additions & 0 deletions src/en/guide/async/events/notifying.gdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The @Events@ trait also provides methods for notifying of events. For example:

{code}
notify "myEvent", "myData"
sendAndReceive "myEvent", "myData", {
println "Got response!"
}
{code}
4 changes: 4 additions & 0 deletions src/en/guide/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ webServices:
async:
title: Asynchronous Programming
promises: Promises
events:
title: Events
consuming: Consuming Events
notifying: Event Notification
asyncGorm: Asynchronous GORM
asyncRequests: Asynchronous Request Handling
asyncServletApi: Servlet 3.0 Async
Expand Down

0 comments on commit 715ae44

Please sign in to comment.