pubsub

package
v0.0.0-...-4db19ce Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2019 License: MIT Imports: 6 Imported by: 1

README

Godoc

Golang OpenChirp PubSub library

This hold the Golang pubsub package which supplies the pure PubSub interface library for OpenChirp.

Documentation

Overview

Package pubsub hold the interfaces and utilities to work with the PubSub side of the OpenChirp framework

Index

Constants

View Source
const (
	QoSAtMostOnce  = MQTTQoS(0)
	QoSAtLeastOnce = MQTTQoS(1)
	QoSExactlyOnce = MQTTQoS(2)
	QoSUnknown     = MQTTQoS(0xFF)
)

Variables

View Source
var (
	// Sets whether AutoReconnect will be set
	AutoReconnect bool = true
)

Functions

func GenMQTTClientID

func GenMQTTClientID(prefix string) (string, error)

GenMQTTClientID generates a random client id for mqtt

Types

type Bridge

type Bridge struct {
	// contains filtered or unexported fields
}

Bridge holds configuration for a PubSub bridge

func NewBridge

func NewBridge(pubsuba, pubsubb PubSub, log *logrus.Logger) *Bridge

NewBridge instantiates a PubSub bridge that allows you to map topics from one pubsub interface to another and the reverse. The log is used to declare errors when publishing asynchronously.

func (*Bridge) AddFwd

func (b *Bridge) AddFwd(deviceid, topica string, callback func(pubsubb PubSub, topica string, payload []byte) error) error

func (*Bridge) AddLinkFwd

func (b *Bridge) AddLinkFwd(deviceid, topica string, topicb ...string) error

func (*Bridge) AddLinkRev

func (b *Bridge) AddLinkRev(deviceid, topicb string, topica ...string) error

func (*Bridge) AddRev

func (b *Bridge) AddRev(deviceid, topicb string, callback func(pubsuba PubSub, topicb string, payload []byte) error) error

func (*Bridge) IsDeviceLinked

func (b *Bridge) IsDeviceLinked(deviceid string) bool

func (*Bridge) IsLinkFwd

func (b *Bridge) IsLinkFwd(deviceid, topica string) bool

func (*Bridge) IsLinkRev

func (b *Bridge) IsLinkRev(deviceid, topicb string) bool

func (*Bridge) RemoveLinksAll

func (b *Bridge) RemoveLinksAll(deviceid string) error

type MQTTClient

type MQTTClient struct {
	// contains filtered or unexported fields
}

func NewMQTTBridgeClient

func NewMQTTBridgeClient(
	brokerURI, user, pass string,
	defaultQoS MQTTQoS,
	defaultPersistence bool) (*MQTTClient, error)

NewMQTTBridgeClient creates and connects an MQTT client that implements the PubSub interface. This special variant will indicate to the broker that you are operating as a MQTT bridge. In this case, you will not receive an echo of messages you publish to a topic you have subscribed to. Note, this is not an official MQTT feature and is only supported by a few brokers. Checkout https://github.com/mqtt/mqtt.github.io/wiki/bridge_protocol for more info.

func NewMQTTClient

func NewMQTTClient(
	brokerURI, user, pass string,
	defaultQoS MQTTQoS,
	defaultPersistence bool) (*MQTTClient, error)

NewMQTTClient creates and connects an MQTT client that implements the PubSub interface

func NewMQTTWillBridgeClient

func NewMQTTWillBridgeClient(
	brokerURI, user, pass string,
	defaultQoS MQTTQoS,
	defaultPersistence bool,
	willTopic string,
	willPayload []byte) (*MQTTClient, error)

NewMQTTWillBridgeClient creates and connects an MQTT client that implements the PubSub interface and sets a will message. This special variant will indicate to the broker that you are operating as a MQTT bridge. In this case, you will not receive an echo of messages you publish to a topic you have subscribed to. Note, this is not an official MQTT feature and is only supported by a few brokers. Checkout https://github.com/mqtt/mqtt.github.io/wiki/bridge_protocol for more info.

func NewMQTTWillClient

func NewMQTTWillClient(
	brokerURI, user, pass string,
	defaultQoS MQTTQoS,
	defaultPersistence bool,
	willTopic string,
	willPayload []byte) (*MQTTClient, error)

NewMQTTWillClient creates and connects an MQTT client that implements the PubSub interface and sets a will message.

func (*MQTTClient) Disconnect

func (c *MQTTClient) Disconnect()

func (*MQTTClient) Publish

func (c *MQTTClient) Publish(topic string, payload interface{}) error

func (*MQTTClient) Subscribe

func (c *MQTTClient) Subscribe(topic string, callback func(topic string, payload []byte)) error

func (*MQTTClient) Unsubscribe

func (c *MQTTClient) Unsubscribe(topics ...string) error

type MQTTQoS

type MQTTQoS byte

func ParseMQTTQoS

func ParseMQTTQoS(QoS string) MQTTQoS

type PubSub

type PubSub interface {
	Subscribe(topic string, callback func(topic string, payload []byte)) error
	Unsubscribe(topics ...string) error
	Publish(topic string, payload interface{}) error
}

PubSub is the most basic PubSub interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL