amqp

package
v2.5.4 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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
)
View Source
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 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

type ChannelClient interface {
	Open() error
	io.Closer
}

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

func NewClient

func NewClient(ctx log.Interface, username, password, host string) Client

NewClient creates a new DefaultClient

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 (c *DefaultPublisher) PublishDownlink(dataDown types.DownlinkMessage) error

PublishDownlink publishes a downlink message to the AMQP broker

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 (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 (s *DefaultSubscriber) SubscribeAppDownlink(appID string, handler DownlinkHandler) error

SubscribeAppDownlink subscribes to all downlink messages for the given application

func (s *DefaultSubscriber) SubscribeAppUplink(appID string, handler UplinkHandler) error

SubscribeAppUplink subscribes to all uplink messages for the given application

func (s *DefaultSubscriber) SubscribeDeviceDownlink(appID, devID string, handler DownlinkHandler) error

SubscribeDeviceDownlink subscribes to all downlink messages for the given application and device

func (s *DefaultSubscriber) SubscribeDeviceUplink(appID, devID string, handler UplinkHandler) error

SubscribeDeviceUplink subscribes to all uplink messages for the given application and device

func (s *DefaultSubscriber) SubscribeDownlink(handler DownlinkHandler) error

SubscribeDownlink subscribes to all downlink messages that the current user has access to

func (s *DefaultSubscriber) SubscribeUplink(handler UplinkHandler) error

SubscribeUplink subscribes to all uplink messages that the current user has access to

type DeviceKey

type DeviceKey struct {
	AppID string
	DevID string
	Type  DeviceKeyType
	Field string
}

DeviceKey represents an AMQP routing key for devices

func ParseDeviceKey

func ParseDeviceKey(key string) (*DeviceKey, error)

ParseDeviceKey parses an AMQP device routing key string to a DeviceKey struct

func (DeviceKey) String

func (t DeviceKey) String() string

String implements the Stringer interface

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
}

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
}

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

Jump to

Keyboard shortcuts

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