Permalink
Browse files

Added configuration to the application

  • Loading branch information...
1 parent c37878a commit d5c354163654dd6fd30e3c95affab439bf968084 @jettro committed Oct 30, 2012
@@ -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."
}
-
}
@@ -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()
@@ -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',
@@ -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.");
+logger.info("The notification module is started.");
@@ -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"

0 comments on commit d5c3541

Please sign in to comment.