Fix the mqtt broker connect. Add to default brokers in cmd
This commit is contained in:
parent
d74cf95278
commit
eecdeaae99
@ -27,10 +27,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/micro/go-micro/broker"
|
||||
"github.com/micro/go-micro/cmd"
|
||||
|
||||
"github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/micro/go-micro/broker"
|
||||
)
|
||||
|
||||
type mqttBroker struct {
|
||||
@ -41,7 +39,6 @@ type mqttBroker struct {
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
cmd.DefaultBrokers["mqtt"] = NewBroker
|
||||
}
|
||||
|
||||
func setAddrs(addrs []string) []string {
|
||||
@ -160,9 +157,11 @@ func (m *mqttBroker) Address() string {
|
||||
}
|
||||
|
||||
func (m *mqttBroker) Connect() error {
|
||||
t := m.client.Connect()
|
||||
if t := m.client.Connect(); t.Wait() && t.Error() != nil {
|
||||
return t.Error()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mqttBroker) Disconnect() error {
|
||||
m.client.Disconnect(0)
|
||||
@ -201,7 +200,7 @@ func (m *mqttBroker) Subscribe(topic string, h broker.Handler, opts ...broker.Su
|
||||
}
|
||||
})
|
||||
|
||||
if t.Error() != nil {
|
||||
if t.Wait() && t.Error() != nil {
|
||||
return nil, t.Error()
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/micro/cli"
|
||||
"github.com/micro/go-micro/broker"
|
||||
"github.com/micro/go-micro/broker/mqtt"
|
||||
"github.com/micro/go-micro/client"
|
||||
"github.com/micro/go-micro/registry"
|
||||
"github.com/micro/go-micro/selector"
|
||||
@ -118,6 +119,7 @@ var (
|
||||
|
||||
DefaultBrokers = map[string]func(...broker.Option) broker.Broker{
|
||||
"http": broker.NewBroker,
|
||||
"mqtt": mqtt.NewBroker,
|
||||
}
|
||||
|
||||
DefaultRegistries = map[string]func(...registry.Option) registry.Registry{
|
||||
|
Loading…
Reference in New Issue
Block a user