Skip to content

Commit

Permalink
Added configuration to the application
Browse files Browse the repository at this point in the history
  • Loading branch information
jettro committed Oct 30, 2012
1 parent c37878a commit d5c3541
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 32 deletions.
55 changes: 41 additions & 14 deletions office-events/app/App.groovy
@@ -1,30 +1,57 @@
/** /**
* Main vertivle for the office events application. This verticle * Main verticle for the office events application. This verticle
* installs the modules and the worker verticle that make the * installs the modules and the worker verticle that make the
* application run. * application do its job.
* *
* @author Jettro Coenradie * @author Jettro Coenradie
*/ */



def log = container.logger def log = container.logger


def mongoConfig = ["db_name": "officeevents", "address": "vertx.persist"] def destiationPersist = "vertx.persist"
def topicAllClients = "message.all.clients"

def appConfig = [
persisterConfig: [
"db_name": "officeevents",
"address": destiationPersist
],
websiteConfig: [
"port": 8080
],
notificationsConfig: [
"all_clients_address": topicAllClients,
"notification_received": "notification.received"
],
invitationConfig: [
"all_clients_address": topicAllClients,
"invitation_new": "message.newinvitation",
"invitation_register": "message.registerinvitation",
"vertx_persist": destiationPersist
],
backupConfig: [
"backup_create":"message.backup.create",
"vertx_persist": destiationPersist
]
]


container.with { container.with {
deployModule('vertx.mongo-persistor-v1.2', mongoConfig, 1) { deploymentID -> deployModule('vertx.mongo-persistor-v1.2', appConfig["persisterConfig"], 1) {
log.info "Started the mongo-persister module." log.info "App: Started the mongo-persister module."
} }
deployModule('website', [:], 4) {deploymentID -> deployModule('website', appConfig["websiteConfig"], 2) {
log.info "Started the website module." log.info "App: Started the website module."
} }
deployModule('notifications') { deploymentID -> deployModule('notifications', appConfig["notificationsConfig"],1) {
log.info "Started the notifications module." log.info "App: Started the notifications module."
} }
deployModule('invitations') { deploymentID -> deployModule('invitations', appConfig["invitationConfig"],1) {
log.info "Started the invitations module." log.info "App: Started the invitations module."
} }
deployWorkerVerticle('app/backup/Backup.groovy') { deploymentID -> deployWorkerVerticle('app/backup/Backup.groovy', appConfig["backupConfig"],1) {
log.info "Started the backup worker verticle." log.info "App: Started the backup worker verticle."
} }

} }


5 changes: 3 additions & 2 deletions office-events/app/backup/Backup.groovy
Expand Up @@ -13,14 +13,15 @@ import org.vertx.groovy.core.eventbus.EventBus
* @author Jettro Coenradie * @author Jettro Coenradie
*/ */


def config = container.config
def log = container.logger def log = container.logger


EventBus eventBus = vertx.eventBus EventBus eventBus = vertx.eventBus


eventBus.registerHandler("message.backup.create") {message -> eventBus.registerHandler(config.backup_create) {message ->
log.info "Start creating the backup and send a reply message that the backup is created." log.info "Start creating the backup and send a reply message that the backup is created."


eventBus.send("vertx.persist", eventBus.send(config.vertx_persist,
["action": "find", "collection": "invites", "matcher": [:]]) { reply -> ["action": "find", "collection": "invites", "matcher": [:]]) { reply ->
log.info reply.body log.info reply.body
def buffer = new Buffer() def buffer = new Buffer()
Expand Down
13 changes: 8 additions & 5 deletions office-events/mods/invitations/invitation.rb
Expand Up @@ -7,14 +7,17 @@
require "vertx" require "vertx"
include Vertx include Vertx


config = Vertx.config
logger = Vertx.logger logger = Vertx.logger


EventBus.register_handler("message.newinvitation") do |message| logger.info config["all_clients_address"]

EventBus.register_handler(config["invitation_new"]) do |message|
message.reply({'message'=>'Thank you for the invitation'}) message.reply({'message'=>'Thank you for the invitation'})
receivedMessage = message.body['message'] receivedMessage = message.body['message']
receivedMaxPersons = message.body['maxpersons'] receivedMaxPersons = message.body['maxpersons']


EventBus.send("vertx.persist", EventBus.send(config["vertx_persist"],
{ {
'action' => 'save', 'action' => 'save',
'collection' => 'invites', 'collection' => 'invites',
Expand All @@ -30,14 +33,14 @@
'maxPersons'=>receivedMaxPersons, 'maxPersons'=>receivedMaxPersons,
'type'=>'invitation' 'type'=>'invitation'
} }
EventBus.publish("message.all.clients",invitation) EventBus.publish(config["all_clients_address"],invitation)
end end
end end


EventBus.register_handler("message.registerinvitation") do |message| EventBus.register_handler(config["invitation_register"]) do |message|
message.reply({'message'=>'You are now welcome to join me'}) message.reply({'message'=>'You are now welcome to join me'})


EventBus.send("vertx.persist", EventBus.send(config["vertx_persist"],
{ {
'action' => 'update', 'action' => 'update',
'collection' => 'invites', 'collection' => 'invites',
Expand Down
7 changes: 4 additions & 3 deletions office-events/mods/notifications/notification.js
Expand Up @@ -6,6 +6,7 @@


load('vertx.js'); load('vertx.js');


var config = vertx.config;
var logger = vertx.logger; var logger = vertx.logger;


var eventBus = vertx.eventBus; var eventBus = vertx.eventBus;
Expand All @@ -14,9 +15,9 @@ var handler = function (message) {
var notification = JSON.parse(message); var notification = JSON.parse(message);
logger.info("Received a notification" + notification.message); logger.info("Received a notification" + notification.message);
notification.type = "notification"; notification.type = "notification";
eventBus.publish("message.all.clients", notification); eventBus.publish(config.all_clients_address, notification);
}; };


eventBus.registerHandler("notification.received", handler); eventBus.registerHandler(config.notification_received, handler);


logger.info("Started the notification module."); logger.info("The notification module is started.");
12 changes: 4 additions & 8 deletions office-events/mods/website/BasicHttpServer.groovy
Expand Up @@ -7,15 +7,11 @@ import org.vertx.groovy.core.http.impl.DefaultHttpServer
* *
* @author Jettro Coenradie * @author Jettro Coenradie
*/ */

def config = container.config
def log = container.logger def log = container.logger
EventBus eventBus = vertx.eventBus


eventBus.registerHandler("message.send.invitation") {message -> EventBus eventBus = vertx.eventBus
def theMessage = message.body
theMessage.put("type", "invitation")
log.info "Received a message to send to a client ${theMessage}"
eventBus.publish("message.forclients", theMessage)
}


RouteMatcher routeMatcher = new RouteMatcher() RouteMatcher routeMatcher = new RouteMatcher()


Expand All @@ -42,6 +38,6 @@ server.requestHandler(routeMatcher.asClosure())


vertx.createSockJSServer(server).bridge(prefix: '/eventbus', [[:]], [[:]]) vertx.createSockJSServer(server).bridge(prefix: '/eventbus', [[:]], [[:]])


server.listen(8080) server.listen(config.port)


log.info "The http server is started" log.info "The http server is started"

0 comments on commit d5c3541

Please sign in to comment.