Commits

Marcus von Appen  committed 94dd155

- Added -c command line argument to load a specific configuration file

  • Participants
  • Parent commits 82b5702

Comments (0)

Files changed (5)

 build:
 	@mkdir -p ${DEPLOYDIR};
 	@echo "Building application ${NAME}...";
-	@${GO} build -o ${DEPLOYDIR}/${NAME} ${ROOTPKG};
-	@cp -rf ${SRCDIR}/data/* ${DEPLOYDIR};
+	@${GO} build -o ${DEPLOYDIR}/${NAME} ${ROOTPKG}
+	@cp -rf ${SRCDIR}/data/* ${DEPLOYDIR}
 
 doc:
-	@cd ${DOCDIR} && make html;
+	@cd ${DOCDIR} && make html
 
 run: build
-	cd ${DEPLOYDIR} && ./${NAME};
+	cd ${DEPLOYDIR} && ./${NAME}
 
 dist: clean
 	@DEPLOYDIR=${DEPLOYDIR}/${DISTNAME} make build
 		${ZIP} ${DISTNAME}-${GOOS}_${GOARCH}.zip ${DISTNAME}; \
 		echo "Creating TAR package"; \
 		${TAR} ${DISTNAME}-${GOOS}_${GOARCH}.tar.xz ${DISTNAME};
+
+# Tests
+test-load: build
+	@cd ${DEPLOYDIR} && ./${NAME} -c ${SRCDIR}/test/load/load.conf
 )
 
 var (
+	flagConfig  = flag.String("c", "", "Configuration file to load")
 	flagDaemon  = flag.Bool("d", false, "Run in daemon mode")
 	flagHelp    = flag.Bool("h", false, "Print the help")
 	flagInspect = flag.Bool("i", false, "Inspect the current status")
 	CONF_FILE         = "dmb-service.conf"
 )
 
-const usageMessage = `usage: dmb [-dhip] [-l file]
+const usageMessage = `usage: dmb [-dhip] [-c file] [-l file]
 
 The dmb service provides a simple message broker system with transformation
 capabilities to receive, transform and send content from and to connected
 
 Options:
 
+  -c <file>   Load the configuration from the passed file.
+
   -d          Run dmb as sort-of daemon. This is not a traditional daemon
               process, but merely will cause dmb to create a PID file on
               running.
 	os.Exit(2)
 }
 
-
 func getCfgOrNil(cfg *goconfig.ConfigFile, section string,
 	value string) string {
 	if val, err := cfg.GetString(section, value); err != nil {
 
 	// Read the configuration
 	cfgfile := os.Getenv(ENV_DMB_CONF_FILE)
-	if cfgfile == "" {
+	if *flagConfig != "" {
+		cfgfile = *flagConfig
+	} else if cfgfile == "" {
 		cfgfile = CONF_FILE
 	}
 	conf, err := goconfig.ReadConfigFile(cfgfile)
 		os.Exit(1)
 	}
 	for _, s := range senders {
-		cert := getCfg(conf, "certificates", s)
+		//cert := getCfg(conf, "certificates", s)
 		host := getCfg(conf, "senders", s)
-		broker.AddSender(s, host, cert)
+		broker.AddSender(s, host, "")
 	}
 	receivers, err := conf.GetOptions("receivers")
 	if err != nil {
 		os.Exit(1)
 	}
 	for _, s := range receivers {
-		cert := getCfg(conf, "certificates", s)
+		//cert := getCfg(conf, "certificates", s)
 		host := getCfg(conf, "receivers", s)
-		broker.AddReceiver(s, host, cert)
+		broker.AddReceiver(s, host, "")
 	}
 
 	// Register the transformation services for the main service

File service/broker.go

 // Execute the service on the content of a request
 func (srv *Broker) Transform(service *Service, req *http.Request,
 	args map[string]string) {
-	log.Log.Debug("Transform() for service [%s] invoked", service)
+	log.Log.Debugf("Transform() for service [%s] invoked", service.Name)
 	buf, err := ioutil.ReadAll(req.Body)
 	if err != nil {
-		log.Log.Errorf("Error on read: %s", err)
-		return
+	 	log.Log.Errorf("Error on read: %s", err)
+	 	return
 	}
 	// Invalid sender
 	sender, err := srv.getSender(req.RemoteAddr)
 	if err != nil {
-		log.Log.Error(err)
+	 	log.Log.Error(err)
 		return
 	}
 	msg := message.New(sender.Name, service.Name, buf, args)

File service/service.go

 	var seterr error = nil
 	failed := []string{}
 	for _, receiver := range srv.Receivers {
+		if receiver.Address == "null" {
+			log.Log.Debugf("%s is a null receiver, message dropped",
+				receiver.Name)
+			continue
+		}
 		r, err := http.NewRequest("POST", receiver.Address,
 			bytes.NewBuffer(msg.Result))
 		if err != nil {

File test/load/load.conf

+[dmb]
+host = 127.0.0.1:8082
+interval_resend_dead = 0 0/5 * * * *
+
+[storage]
+type = file
+location = ./dump
+
+[log]
+level = 2
+
+[senders]
+joe = 127.0.0.1
+
+[receivers]
+nuller = null
+
+[service-cat]
+sender = joe
+post = /cat
+transform = cat
+receiver = nuller