bail if you cant connect

This commit is contained in:
Asim 2015-05-23 17:55:08 +01:00
parent e192f335da
commit 018183fa49

View File

@ -4,7 +4,9 @@ import (
"fmt" "fmt"
"time" "time"
log "github.com/golang/glog"
"github.com/myodc/go-micro/broker" "github.com/myodc/go-micro/broker"
"github.com/myodc/go-micro/cmd"
) )
var ( var (
@ -16,8 +18,11 @@ func pub() {
i := 0 i := 0
for _ = range tick.C { for _ = range tick.C {
msg := fmt.Sprintf("%d: %s", i, time.Now().String()) msg := fmt.Sprintf("%d: %s", i, time.Now().String())
if err := broker.Publish(topic, []byte(msg)); err != nil {
log.Errorf("[pub] failed: %v", err)
} else {
fmt.Println("[pub] pubbed message:", msg) fmt.Println("[pub] pubbed message:", msg)
broker.Publish(topic, []byte(msg)) }
i++ i++
} }
} }
@ -32,8 +37,14 @@ func sub() {
} }
func main() { func main() {
broker.Init() cmd.Init()
broker.Connect()
if err := broker.Init(); err != nil {
log.Fatalf("Broker Init error: %v", err)
}
if err := broker.Connect(); err != nil {
log.Fatalf("Broker Connect error: %v", err)
}
go pub() go pub()
go sub() go sub()