sbcontroller

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sbcontroller creates a wrapper around azure-service-bus-go to control how sb-shovel should interact with a Service Bus queue.

As azure-service-bus-go does not expose it's own interfaces, the Controller interface was created to support Dependency Injection, allowing dependencies to mock and test logic without interacting with a queue directly.

Index

Constants

View Source
const (
	ERR_DELETESTATUS     string = "\r[status] completed %d of %d messages"
	ERR_FOUNDPATTERN     string = "[status] identified %s in message"
	ERR_NOMESSAGESTOSEND string = "no messages to send"
	ERR_NOQUEUEOBJECT    string = "no queue to close"
	ERR_NOTFOUND         string = "could not find service bus queue - 404"
	ERR_QUEUEEMPTY       string = "no messages to pull"
	ERR_UNAUTHORISED     string = "unauthorised or inaccessible service bus. please confirm details - 401"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller interface {
	DeleteOneMessage() error
	DeleteManyMessages(errChan chan error, total int, delay bool)
	DisconnectQueues() error
	DisconnectSource() error
	DisconnectTarget() error
	GetSourceQueueCount() (int, error)
	GetTargetQueueCount() (int, error)
	ReadSourceQueue(outChan chan []string, errChan chan error, maxWrite int)
	RequeueOneMessage() error
	RequeueManyMessages(total int) error
	SendJsonMessage(q bool, data []byte) error
	SendManyJsonMessages(q bool, data [][]byte) error
	SetupSourceQueue(name string, dlq, purge bool) error
	SetupTargetQueue(name string, dlq, purge bool) error
	TidyMessages(errChan chan error, rex *regexp.Regexp, execute bool, total int)
	// contains filtered or unexported methods
}

Controller is a generic wrapper to control interactions with a Service Bus client.

func NewServiceBusController added in v0.6.0

func NewServiceBusController(conn string) (Controller, error)

NewServiceBusController builds and returns a ServiceBusController, initialising the azure-service-bus-go package client using a supplied connection string.

type ServiceBusController

type ServiceBusController struct {
	Controller
	// contains filtered or unexported fields
}

ServiceBusController is the concrete implementation for the azure-service-bus-go package.

func (*ServiceBusController) DeleteManyMessages

func (sb *ServiceBusController) DeleteManyMessages(errChan chan error, total int, delay bool)

DeleteManyMessages concurrently receives and completes many messages.

Given a total number (e.g. the current value on the queue), this process will run until that many messages have been deleted.

Choosing to action a delay will slow down the operation per 50 messages.

Errors are returned via a channel.

func (*ServiceBusController) DeleteOneMessage

func (sb *ServiceBusController) DeleteOneMessage() error

DeleteOneMessage receives then completes exactly ONE message from the queue. An error is returned if a problem was encountered.

func (*ServiceBusController) DisconnectQueues

func (sb *ServiceBusController) DisconnectQueues() error

DisconnectQueues performs both DisconnectSource and DisconnectTarget.

func (*ServiceBusController) DisconnectSource

func (sb *ServiceBusController) DisconnectSource() error

DisconnectSource breaks the connection for the queue assigned to the internal source queue attribute on the Controller.

func (*ServiceBusController) DisconnectTarget

func (sb *ServiceBusController) DisconnectTarget() error

DisconnectSource breaks the connection for the queue assigned to the internal target queue attribute on the Controller.

func (*ServiceBusController) GetSourceQueueCount

func (sb *ServiceBusController) GetSourceQueueCount() (int, error)

GetSourceQueueCount retrieves the count of messages on the configured source queue.

func (*ServiceBusController) GetTargetQueueCount

func (sb *ServiceBusController) GetTargetQueueCount() (int, error)

GetTargetQueueCount retrieves teh count of messages on the configured target queue.

func (*ServiceBusController) ReadSourceQueue

func (sb *ServiceBusController) ReadSourceQueue(outChan chan []string, errChan chan error, maxWrite int)

ReadSourceQueue peeks messages on the configured source queue, returning a batch of messages, controlled by the maxWrite variable, to a channel.

Errors are returned on a separate channel.

func (*ServiceBusController) RequeueManyMessages added in v0.5.0

func (sb *ServiceBusController) RequeueManyMessages(total int) error

RequeueManyMessages receives from a source queue, sends as new to the target queue, then completes from the source queue. This is performed on many messages, controlled by the total parameter.

func (*ServiceBusController) RequeueOneMessage added in v0.5.0

func (sb *ServiceBusController) RequeueOneMessage() error

RequeueOneMessage receives exactly ONE message from the source queue, resends the Data property of a message to the target queue, then completes from the source queue.

An error is returned if a problem was encountered.

func (*ServiceBusController) SendJsonMessage

func (sb *ServiceBusController) SendJsonMessage(q bool, data []byte) error

SendJsonMessage sends to either the source or target queue, passing in solely the message content.

If q is true, the message is sent to target. If q is false, the message is sent to the source.

The message is sent in JSON format.

func (*ServiceBusController) SendManyJsonMessages

func (sb *ServiceBusController) SendManyJsonMessages(q bool, data [][]byte) error

SendManyJsonMessages sends many messages, from an array, to either the source or target.

If q is true, the message is sent to target. If q is false, the message is sent to source.

The message is sent in JSON format.

func (*ServiceBusController) SetupSourceQueue

func (sb *ServiceBusController) SetupSourceQueue(name string, dlq, purge bool) error

SetupSourceQueue configures the queue connection, by name and whether the dead letter queue should be treated as the queue.

Specifying purge as true will increase the prefetch count for faster processing of many messages.

func (*ServiceBusController) SetupTargetQueue

func (sb *ServiceBusController) SetupTargetQueue(name string, dlq, purge bool) error

SetupTargetQueue configures the queue connection, by name and whether the dead letter queue should be treated as the queue.

Specifying purge as true will increase the prefetch count for faster processing of many messages.

func (*ServiceBusController) TidyMessages added in v0.6.0

func (sb *ServiceBusController) TidyMessages(errChan chan error, rex *regexp.Regexp, execute bool, total int)

TidyMessages concurrently receives and identifies messages to be deleted based on a supplied regex pattern.

WARNING: This operation will not delete messages by default. Provide execute as true to trigger deletion. Messages not matched are abandoned.

Jump to

Keyboard shortcuts

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