2016-04-23 00:06:29 +01:00
|
|
|
package mqtt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/eclipse/paho.mqtt.golang"
|
|
|
|
"github.com/micro/go-micro/broker"
|
|
|
|
)
|
|
|
|
|
|
|
|
// mqttPub is a broker.Publication
|
|
|
|
type mqttPub struct {
|
2016-04-25 22:15:01 +01:00
|
|
|
topic string
|
|
|
|
msg *broker.Message
|
2016-04-23 00:06:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// mqttPub is a broker.Subscriber
|
|
|
|
type mqttSub struct {
|
|
|
|
opts broker.SubscribeOptions
|
|
|
|
topic string
|
|
|
|
client mqtt.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mqttPub) Ack() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mqttPub) Topic() string {
|
2016-04-25 22:15:01 +01:00
|
|
|
return m.topic
|
2016-04-23 00:06:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mqttPub) Message() *broker.Message {
|
2016-04-25 22:15:01 +01:00
|
|
|
return m.msg
|
2016-04-23 00:06:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mqttSub) Options() broker.SubscribeOptions {
|
|
|
|
return m.opts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mqttSub) Topic() string {
|
|
|
|
return m.topic
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mqttSub) Unsubscribe() error {
|
|
|
|
t := m.client.Unsubscribe(m.topic)
|
|
|
|
return t.Error()
|
|
|
|
}
|