Documentation ¶
Index ¶
- Variables
- type AppEventHandler
- type ApplicationKey
- type ApplicationKeyType
- type ChannelClient
- type Client
- type DefaultChannelClient
- type DefaultClient
- func (c *DefaultClient) Connect() error
- func (c *DefaultClient) Disconnect()
- func (c *DefaultClient) GetChannel() (*AMQP.Channel, error)
- func (c *DefaultClient) IsConnected() bool
- func (c *DefaultClient) NewPublisher(exchange string) Publisher
- func (c *DefaultClient) NewSubscriber(exchange, name string, durable, autoDelete bool) Subscriber
- type DefaultPublisher
- func (c *DefaultPublisher) PublishAppEvent(appID string, eventType types.EventType, payload interface{}) error
- func (c *DefaultPublisher) PublishDeviceEvent(appID string, devID string, eventType types.EventType, payload interface{}) error
- func (c *DefaultPublisher) PublishDownlink(dataDown types.DownlinkMessage) error
- func (c *DefaultPublisher) PublishUplink(dataUp types.UplinkMessage) error
- type DefaultSubscriber
- func (s *DefaultSubscriber) ConsumeUplink(queue string, handler UplinkHandler) error
- func (s *DefaultSubscriber) QueueBind(name, key string) error
- func (s *DefaultSubscriber) QueueDeclare() (string, error)
- func (s *DefaultSubscriber) QueueUnbind(name, key string) error
- func (s *DefaultSubscriber) SubscribeAppDownlink(appID string, handler DownlinkHandler) error
- func (s *DefaultSubscriber) SubscribeAppEvents(appID string, eventType types.EventType, handler AppEventHandler) error
- func (s *DefaultSubscriber) SubscribeAppUplink(appID string, handler UplinkHandler) error
- func (s *DefaultSubscriber) SubscribeDeviceDownlink(appID, devID string, handler DownlinkHandler) error
- func (s *DefaultSubscriber) SubscribeDeviceEvents(appID string, devID string, eventType types.EventType, ...) error
- func (s *DefaultSubscriber) SubscribeDeviceUplink(appID, devID string, handler UplinkHandler) error
- func (s *DefaultSubscriber) SubscribeDownlink(handler DownlinkHandler) error
- func (s *DefaultSubscriber) SubscribeUplink(handler UplinkHandler) error
- type DeviceEventHandler
- type DeviceKey
- type DeviceKeyType
- type DownlinkHandler
- type Publisher
- type Subscriber
- type UplinkHandler
Constants ¶
This section is empty.
Variables ¶
var ( // ConnectRetries says how many times the client should retry a failed connection ConnectRetries = 10 // ConnectRetryDelay says how long the client should wait between retries ConnectRetryDelay = time.Second )
var ( // PrefetchCount represents the number of messages to prefetch before the AMQP server requires acknowledgment PrefetchCount = 3 // PrefetchSize represents the number of bytes to prefetch before the AMQP server requires acknowledgment PrefetchSize = 0 )
Functions ¶
This section is empty.
Types ¶
type AppEventHandler ¶ added in v2.6.1
type AppEventHandler func(sub Subscriber, appID string, eventType types.EventType, payload []byte)
AppEventHandler is called for events
type ApplicationKey ¶
type ApplicationKey struct { AppID string Type ApplicationKeyType Field string }
ApplicationKey represents an AMQP topic for applications
func ParseApplicationKey ¶
func ParseApplicationKey(key string) (*ApplicationKey, error)
ParseApplicationKey parses an AMQP application routing key string to an ApplicationKey struct
func (ApplicationKey) String ¶
func (t ApplicationKey) String() string
String implements the Stringer interface
type ApplicationKeyType ¶
type ApplicationKeyType string
ApplicationKeyType represents an AMQP application routing key
const (
AppEvents ApplicationKeyType = "events"
)
Topic types for Applications
type ChannelClient ¶
ChannelClient represents an AMQP channel client
type Client ¶
type Client interface { Connect() error Disconnect() IsConnected() bool NewPublisher(exchange string) Publisher NewSubscriber(exchange, name string, durable, autoDelete bool) Subscriber }
Client connects to an AMQP server
type DefaultChannelClient ¶
type DefaultChannelClient struct {
// contains filtered or unexported fields
}
DefaultChannelClient represents the default client of an AMQP channel
func (*DefaultChannelClient) Close ¶
func (p *DefaultChannelClient) Close() error
Close closes the channel
func (*DefaultChannelClient) Open ¶
func (p *DefaultChannelClient) Open() error
Open opens a new channel and declares the exchange
type DefaultClient ¶
type DefaultClient struct {
// contains filtered or unexported fields
}
DefaultClient is the default AMQP client for The Things Network
func (*DefaultClient) Connect ¶
func (c *DefaultClient) Connect() error
Connect to the AMQP server. It will retry for ConnectRetries times with a delay of ConnectRetryDelay between retries
func (*DefaultClient) Disconnect ¶
func (c *DefaultClient) Disconnect()
Disconnect from the AMQP server
func (*DefaultClient) GetChannel ¶ added in v2.4.0
func (c *DefaultClient) GetChannel() (*AMQP.Channel, error)
GetChannel gets a new AMQP channel
func (*DefaultClient) IsConnected ¶
func (c *DefaultClient) IsConnected() bool
IsConnected returns true if there is a connection to the AMQP server.
func (*DefaultClient) NewPublisher ¶
func (c *DefaultClient) NewPublisher(exchange string) Publisher
NewPublisher returns a new topic publisher on the specified exchange
func (*DefaultClient) NewSubscriber ¶
func (c *DefaultClient) NewSubscriber(exchange, name string, durable, autoDelete bool) Subscriber
NewSubscriber returns a new topic subscriber on the specified exchange
type DefaultPublisher ¶
type DefaultPublisher struct {
DefaultChannelClient
}
DefaultPublisher represents the default AMQP publisher
func (*DefaultPublisher) PublishAppEvent ¶ added in v2.6.1
func (c *DefaultPublisher) PublishAppEvent(appID string, eventType types.EventType, payload interface{}) error
PublishAppEvent publishes an event to the topic for application events of the given type it will marshal the payload to json
func (*DefaultPublisher) PublishDeviceEvent ¶ added in v2.6.1
func (c *DefaultPublisher) PublishDeviceEvent(appID string, devID string, eventType types.EventType, payload interface{}) error
PublishDeviceEvent publishes an event to the topic for device events of the given type it will marshal the payload to json
func (*DefaultPublisher) PublishDownlink ¶
func (c *DefaultPublisher) PublishDownlink(dataDown types.DownlinkMessage) error
PublishDownlink publishes a downlink message to the AMQP broker
func (*DefaultPublisher) PublishUplink ¶
func (c *DefaultPublisher) PublishUplink(dataUp types.UplinkMessage) error
PublishUplink publishes an uplink message to the AMQP broker
type DefaultSubscriber ¶
type DefaultSubscriber struct { DefaultChannelClient // contains filtered or unexported fields }
DefaultSubscriber represents the default AMQP subscriber
func (*DefaultSubscriber) ConsumeUplink ¶ added in v2.2.1
func (s *DefaultSubscriber) ConsumeUplink(queue string, handler UplinkHandler) error
ConsumeUplink consumes uplink messages in a specific queue
func (*DefaultSubscriber) QueueBind ¶ added in v2.2.1
func (s *DefaultSubscriber) QueueBind(name, key string) error
QueueBind binds the routing key to the specified queue
func (*DefaultSubscriber) QueueDeclare ¶ added in v2.2.1
func (s *DefaultSubscriber) QueueDeclare() (string, error)
QueueDeclare declares the queue on the AMQP broker
func (*DefaultSubscriber) QueueUnbind ¶ added in v2.2.1
func (s *DefaultSubscriber) QueueUnbind(name, key string) error
QueueUnbind unbinds the routing key from the specified queue
func (*DefaultSubscriber) SubscribeAppDownlink ¶
func (s *DefaultSubscriber) SubscribeAppDownlink(appID string, handler DownlinkHandler) error
SubscribeAppDownlink subscribes to all downlink messages for the given application
func (*DefaultSubscriber) SubscribeAppEvents ¶ added in v2.6.1
func (s *DefaultSubscriber) SubscribeAppEvents(appID string, eventType types.EventType, handler AppEventHandler) error
SubscribeAppEvents subscribes to events of the given type for the given application. In order to subscribe to application events from all applications the user has access to, pass an empty string as appID.
func (*DefaultSubscriber) SubscribeAppUplink ¶
func (s *DefaultSubscriber) SubscribeAppUplink(appID string, handler UplinkHandler) error
SubscribeAppUplink subscribes to all uplink messages for the given application
func (*DefaultSubscriber) SubscribeDeviceDownlink ¶
func (s *DefaultSubscriber) SubscribeDeviceDownlink(appID, devID string, handler DownlinkHandler) error
SubscribeDeviceDownlink subscribes to all downlink messages for the given application and device
func (*DefaultSubscriber) SubscribeDeviceEvents ¶ added in v2.6.1
func (s *DefaultSubscriber) SubscribeDeviceEvents(appID string, devID string, eventType types.EventType, handler DeviceEventHandler) error
SubscribeDeviceEvents subscribes to events of the given type for the given device. In order to subscribe to events from all devices within an application, pass an empty string as devID. In order to subscribe to all events from all devices in all applications the user has access to, pass an empty string as appID.
func (*DefaultSubscriber) SubscribeDeviceUplink ¶
func (s *DefaultSubscriber) SubscribeDeviceUplink(appID, devID string, handler UplinkHandler) error
SubscribeDeviceUplink subscribes to all uplink messages for the given application and device
func (*DefaultSubscriber) SubscribeDownlink ¶
func (s *DefaultSubscriber) SubscribeDownlink(handler DownlinkHandler) error
SubscribeDownlink subscribes to all downlink messages that the current user has access to
func (*DefaultSubscriber) SubscribeUplink ¶
func (s *DefaultSubscriber) SubscribeUplink(handler UplinkHandler) error
SubscribeUplink subscribes to all uplink messages that the current user has access to
type DeviceEventHandler ¶ added in v2.6.1
type DeviceEventHandler func(sub Subscriber, appID string, devID string, eventType types.EventType, payload []byte)
DeviceEventHandler is called for events
type DeviceKey ¶
type DeviceKey struct { AppID string DevID string Type DeviceKeyType Field string }
DeviceKey represents an AMQP routing key for devices
func ParseDeviceKey ¶
ParseDeviceKey parses an AMQP device routing key string to a DeviceKey struct
type DeviceKeyType ¶
type DeviceKeyType string
DeviceKeyType represents the type of a device topic
const ( DeviceEvents DeviceKeyType = "events" DeviceUplink DeviceKeyType = "up" DeviceDownlink DeviceKeyType = "down" )
Topic types for Devices
type DownlinkHandler ¶
type DownlinkHandler func(subscriber Subscriber, appID string, devID string, req types.DownlinkMessage)
DownlinkHandler is called for downlink messages
type Publisher ¶
type Publisher interface { ChannelClient PublishUplink(dataUp types.UplinkMessage) error PublishDownlink(dataDown types.DownlinkMessage) error PublishDeviceEvent(appID string, devID string, eventType types.EventType, payload interface{}) error PublishAppEvent(appID string, eventType types.EventType, payload interface{}) error }
Publisher represents a publisher for uplink messages
type Subscriber ¶
type Subscriber interface { ChannelClient QueueDeclare() (string, error) QueueBind(name, key string) error QueueUnbind(name, key string) error SubscribeDeviceUplink(appID, devID string, handler UplinkHandler) error SubscribeAppUplink(appID string, handler UplinkHandler) error SubscribeUplink(handler UplinkHandler) error ConsumeUplink(queue string, handler UplinkHandler) error SubscribeDeviceDownlink(appID, devID string, handler DownlinkHandler) error SubscribeAppDownlink(appID string, handler DownlinkHandler) error SubscribeDownlink(handler DownlinkHandler) error SubscribeDeviceEvents(appID string, devID string, eventType types.EventType, handler DeviceEventHandler) error SubscribeAppEvents(appID string, eventType types.EventType, handler AppEventHandler) error }
Subscriber represents a subscriber for uplink messages
type UplinkHandler ¶
type UplinkHandler func(subscriber Subscriber, appID string, devID string, req types.UplinkMessage)
UplinkHandler is called for uplink messages