1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-12 08:23:58 +02:00
go-micro/broker/mqtt/mqtt_handler.go
2016-04-25 22:15:01 +01:00

45 lines
710 B
Go

package mqtt
import (
"github.com/eclipse/paho.mqtt.golang"
"github.com/micro/go-micro/broker"
)
// mqttPub is a broker.Publication
type mqttPub struct {
topic string
msg *broker.Message
}
// 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 {
return m.topic
}
func (m *mqttPub) Message() *broker.Message {
return m.msg
}
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()
}