messaging

package
v0.0.0-...-f2c9a1f Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: MIT Imports: 6 Imported by: 7

Documentation

Index

Constants

View Source
const (
	//PingCommandContentType is the content type for a ping command
	PingCommandContentType = "application/vnd-ping-command"
	//PongResponseContentType is the content type for a pong response
	PongResponseContentType = "application/vnd-pong-response"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandHandler

type CommandHandler func(CommandMessageWrapper) error

CommandHandler is a callback type to be used for dispatching incoming commands

func NewPingCommandHandler

func NewPingCommandHandler(ctx Context) CommandHandler

NewPingCommandHandler returns a callback function to be called when ping commands are received

type CommandMessage

type CommandMessage interface {
	ContentType() string
}

CommandMessage is an interface used when sending commands

func NewPingCommand

func NewPingCommand() CommandMessage

NewPingCommand instantiates a new ping command

func NewPongResponse

func NewPongResponse(ping PingCommand) CommandMessage

NewPongResponse instantiates a new pong response from a ping command

type CommandMessageWrapper

type CommandMessageWrapper interface {
	Body() []byte
	RespondWith(CommandMessage) error
}

CommandMessageWrapper is used to wrap an incoming command message

type Config

type Config struct {
	ServiceName string
	Host        string
	User        string
	Password    string
}

Config is an encapsulating context that wraps configuration information used by the initialization methods of the messaging library

func LoadConfiguration

func LoadConfiguration(serviceName string) Config

LoadConfiguration loads configuration values from RABBITMQ_HOST, RABBITMQ_USER and RABBITMQ_PASS. The username and password defaults to the bitnami ootb values for local testing.

type Context

type Context interface {
	NoteToSelf(command CommandMessage) error
	SendCommandTo(command CommandMessage, key string) error
	SendResponseTo(response CommandMessage, key string) error
	PublishOnTopic(message TopicMessage) error
	Close()
	RegisterCommandHandler(contentType string, handler CommandHandler) error
	RegisterTopicMessageHandler(routingKey string, handler TopicMessageHandler)
}

Context encapsulates the underlying messaging primitives, as well as their associated configuration

func Initialize

func Initialize(cfg Config) (Context, error)

Initialize takes a Config parameter and initializes a connection, channel, topic exchange, command exchange and service specific command and response queues. Retries every 2 seconds until successfull.

type Error

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

Error encapsulates a lower level error together with an error message provided by the caller that experienced the error

func (*Error) Error

func (err *Error) Error() string

type IoTHubMessage

type IoTHubMessage struct {
	Origin    IoTHubMessageOrigin `json:"origin"`
	Timestamp string              `json:"timestamp"`
}

type IoTHubMessageOrigin

type IoTHubMessageOrigin struct {
	Device    string  `json:"device"`
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

type PingCommand

type PingCommand struct {
	Cmd       string    `json:"cmd"`
	Timestamp time.Time `json:"timestamp"`
}

PingCommand is a utility command to check the messenger connection

func (PingCommand) ContentType

func (cmd PingCommand) ContentType() string

ContentType returns the content type for a ping command

type PongResponse

type PongResponse struct {
	Cmd       string `json:"cmd"`
	PingSent  time.Time
	Timestamp time.Time `json:"timestamp"`
}

PongResponse is a utility response to check the messenger connection

func (PongResponse) ContentType

func (cmd PongResponse) ContentType() string

ContentType returns the content type for a pong response

type TopicMessage

type TopicMessage interface {
	ContentType() string
	TopicName() string
}

TopicMessage is an interface used when sending messages to make sure that messages are sent to the correct topic with correct content type

type TopicMessageHandler

type TopicMessageHandler func(amqp.Delivery)

TopicMessageHandler is a callback type that should be passed to RegisterTopicMessageHandler to receive messages from topics.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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