From d5c354163654dd6fd30e3c95affab439bf968084 Mon Sep 17 00:00:00 2001 From: jettro Date: Tue, 30 Oct 2012 13:13:52 +0100 Subject: [PATCH] Added configuration to the application --- office-events/app/App.groovy | 55 ++++++++++++++----- office-events/app/backup/Backup.groovy | 5 +- office-events/mods/invitations/invitation.rb | 13 +++-- .../mods/notifications/notification.js | 7 ++- .../mods/website/BasicHttpServer.groovy | 12 ++-- 5 files changed, 60 insertions(+), 32 deletions(-) diff --git a/office-events/app/App.groovy b/office-events/app/App.groovy index 670f4b8..d1c3ab5 100644 --- a/office-events/app/App.groovy +++ b/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 - * application run. + * application do its job. * * @author Jettro Coenradie */ + + + 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 { - deployModule('vertx.mongo-persistor-v1.2', mongoConfig, 1) { deploymentID -> - log.info "Started the mongo-persister module." + deployModule('vertx.mongo-persistor-v1.2', appConfig["persisterConfig"], 1) { + log.info "App: Started the mongo-persister module." } - deployModule('website', [:], 4) {deploymentID -> - log.info "Started the website module." + deployModule('website', appConfig["websiteConfig"], 2) { + log.info "App: Started the website module." } - deployModule('notifications') { deploymentID -> - log.info "Started the notifications module." + deployModule('notifications', appConfig["notificationsConfig"],1) { + log.info "App: Started the notifications module." } - deployModule('invitations') { deploymentID -> - log.info "Started the invitations module." + deployModule('invitations', appConfig["invitationConfig"],1) { + log.info "App: Started the invitations module." } - deployWorkerVerticle('app/backup/Backup.groovy') { deploymentID -> - log.info "Started the backup worker verticle." + deployWorkerVerticle('app/backup/Backup.groovy', appConfig["backupConfig"],1) { + log.info "App: Started the backup worker verticle." } - } diff --git a/office-events/app/backup/Backup.groovy b/office-events/app/backup/Backup.groovy index 58c4583..3f98ff4 100644 --- a/office-events/app/backup/Backup.groovy +++ b/office-events/app/backup/Backup.groovy @@ -13,14 +13,15 @@ import org.vertx.groovy.core.eventbus.EventBus * @author Jettro Coenradie */ +def config = container.config def log = container.logger 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." - eventBus.send("vertx.persist", + eventBus.send(config.vertx_persist, ["action": "find", "collection": "invites", "matcher": [:]]) { reply -> log.info reply.body def buffer = new Buffer() diff --git a/office-events/mods/invitations/invitation.rb b/office-events/mods/invitations/invitation.rb index 8c38100..950eb4f 100644 --- a/office-events/mods/invitations/invitation.rb +++ b/office-events/mods/invitations/invitation.rb @@ -7,14 +7,17 @@ require "vertx" include Vertx +config = Vertx.config 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'}) receivedMessage = message.body['message'] receivedMaxPersons = message.body['maxpersons'] - EventBus.send("vertx.persist", + EventBus.send(config["vertx_persist"], { 'action' => 'save', 'collection' => 'invites', @@ -30,14 +33,14 @@ 'maxPersons'=>receivedMaxPersons, 'type'=>'invitation' } - EventBus.publish("message.all.clients",invitation) + EventBus.publish(config["all_clients_address"],invitation) 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'}) - EventBus.send("vertx.persist", + EventBus.send(config["vertx_persist"], { 'action' => 'update', 'collection' => 'invites', diff --git a/office-events/mods/notifications/notification.js b/office-events/mods/notifications/notification.js index 1e464b6..bae3f00 100644 --- a/office-events/mods/notifications/notification.js +++ b/office-events/mods/notifications/notification.js @@ -6,6 +6,7 @@ load('vertx.js'); +var config = vertx.config; var logger = vertx.logger; var eventBus = vertx.eventBus; @@ -14,9 +15,9 @@ var handler = function (message) { var notification = JSON.parse(message); logger.info("Received a notification" + notification.message); 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."); \ No newline at end of file +logger.info("The notification module is started."); \ No newline at end of file diff --git a/office-events/mods/website/BasicHttpServer.groovy b/office-events/mods/website/BasicHttpServer.groovy index e8cf38c..4aa93b3 100644 --- a/office-events/mods/website/BasicHttpServer.groovy +++ b/office-events/mods/website/BasicHttpServer.groovy @@ -7,15 +7,11 @@ import org.vertx.groovy.core.http.impl.DefaultHttpServer * * @author Jettro Coenradie */ + +def config = container.config def log = container.logger -EventBus eventBus = vertx.eventBus -eventBus.registerHandler("message.send.invitation") {message -> - def theMessage = message.body - theMessage.put("type", "invitation") - log.info "Received a message to send to a client ${theMessage}" - eventBus.publish("message.forclients", theMessage) -} +EventBus eventBus = vertx.eventBus RouteMatcher routeMatcher = new RouteMatcher() @@ -42,6 +38,6 @@ server.requestHandler(routeMatcher.asClosure()) vertx.createSockJSServer(server).bridge(prefix: '/eventbus', [[:]], [[:]]) -server.listen(8080) +server.listen(config.port) log.info "The http server is started" \ No newline at end of file