Documentation ¶
Overview ¶
Package mqsend is a pure go implementation of posix message queue for Linux, using syscalls.
The purpose of this package is to provide a pure go (no cgo) implementation on 64-bit Linux systems to be able to send messages to the posix message queue, which will be consumed by sidecars implemented in baseplate.py. It's never meant to be a complete implementation of message queue features. It does NOT have supports for:
* Non-linux systems (e.g. macOS)
* Non-64-bit systems (e.g. 32-bit Linux)
* Non-send operations (e.g. receive)
If you need those features, this is not the package for you.
Index ¶
Constants ¶
const MessageQueueOpenMode = 0644
MessageQueueOpenMode is the mode used to open message queues.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MessageQueue ¶
type MessageQueue interface { io.Closer // Send sends a message to the queue. // // Caller should always call Send with a context object with deadline set, // or Send might block forever when the queue is full. Send(ctx context.Context, data []byte) error }
MessageQueue represents a Posix Message Queue.
func OpenMessageQueue ¶
func OpenMessageQueue(cfg MessageQueueConfig) (MessageQueue, error)
OpenMessageQueue opens a named message queue.
On Linux systems this returns the real thing. On non-linux systems this just returns a mocked version, see OpenMockMessageQueue.
type MessageQueueConfig ¶
type MessageQueueConfig struct { // Name of the message queue, should not start with "/". Name string // The max number of messages in the queue. MaxQueueSize int64 // The max size in bytes per message. MaxMessageSize int64 }
MessageQueueConfig is the config used in OpenMessageQueue call.
type MessageTooLargeError ¶
type MessageTooLargeError struct { MessageSize int // Note that MaxSize will always be 0 on linux systems, // as we don't store it after send to mq_open syscall. MaxSize int // Note that on non-linux systems Cause will be nil. Cause error }
MessageTooLargeError is the error returned by MessageQueue.Send when the message is larger than the configured max size.
On linux systems it wraps syscall.EMSGSIZE, on other systems (or with MockMessageQueue) it doesn't wrap any other errors.
func (MessageTooLargeError) Error ¶
func (e MessageTooLargeError) Error() string
func (MessageTooLargeError) Unwrap ¶
func (e MessageTooLargeError) Unwrap() error
Unwrap returns the underlying error, if any.
type MockMessageQueue ¶
type MockMessageQueue struct {
// contains filtered or unexported fields
}
MockMessageQueue is a mocked implementation of MessageQueue.
It's implemented with channels.
func OpenMockMessageQueue ¶
func OpenMockMessageQueue(cfg MessageQueueConfig) *MockMessageQueue
OpenMockMessageQueue creates a MockMessageQueue.
The name from the cfg will be ignored.
type TimedOutError ¶
type TimedOutError struct {
Cause error
}
TimedOutError is the error returned by MessageQueue.Send when the operation timed out because of the queue was full.
On linux systems it wraps syscall.ETIMEDOUT, on other systems (or with MockMessageQueue) it wraps context.DeadlineExceeded.
func (TimedOutError) Error ¶
func (e TimedOutError) Error() string
func (TimedOutError) Unwrap ¶
func (e TimedOutError) Unwrap() error
Unwrap returns the underlying error.