rabbitmqtest

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package rabbitmqtest is a small AMQP 0-9-1 broker for tests.

It does not implement headers exchanges (declare returns 540 NOT_IMPLEMENTED), message TTL, priority ordering, queue-type behaviour, or persistence. Those values are stored and, where a reply echoes them, sent back unchanged.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Users  map[string]string
	Vhosts []string
}

Config is the login and vhost set. An empty Users map accepts guest/guest. An empty Vhosts list accepts only "/".

type ConnInfo

type ConnInfo struct {
	Heartbeat uint16
	Name      string
	Vhost     string
	User      string
}

ConnInfo is one connection that finished opening.

type Pub

type Pub struct {
	Exchange     string
	RoutingKey   string
	Body         []byte
	MessageID    string
	ContentType  string
	Expiration   string
	DeliveryMode uint8
	Priority     uint8
	Timestamp    time.Time
	Headers      map[string]any
	Mandatory    bool
}

Pub is one basic.publish the broker accepted into its log, including messages that were then returned as not routed.

type Server

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

Server is an in-memory AMQP 0-9-1 broker.

func Start

func Start(t testingT) *Server

Start listens on 127.0.0.1:0 and accepts connections until the test ends.

func StartTLS

func StartTLS(t testingT) *Server

StartTLS is Start with a certificate the process generated. Clients that verify certificates fail. Clients that skip verification succeed.

func (*Server) Addr

func (s *Server) Addr() string

Addr is host:port.

func (*Server) Apply

func (s *Server) Apply(cfg Config)

Apply replaces the user and vhost sets. Call it before dialing.

func (*Server) Block

func (s *Server) Block(reason string)

Block sends connection.blocked to every open connection.

func (*Server) CloseChannelOn

func (s *Server) CloseChannelOn(method string, code uint16, text string)

CloseChannelOn answers the named method with channel.close.

func (*Server) ConnCount

func (s *Server) ConnCount() int

ConnCount is how many TCP connections were accepted.

func (*Server) Connections

func (s *Server) Connections() []ConnInfo

Connections lists connections that finished connection.open.

func (*Server) Delay

func (s *Server) Delay(d time.Duration)

Delay waits before every reply.

func (*Server) Depth

func (s *Server) Depth(name string) int

Depth is the number of ready messages in the queue.

func (*Server) DropConnectionOn

func (s *Server) DropConnectionOn(method string)

DropConnectionOn closes the TCP connection when the named method arrives.

func (*Server) Methods

func (s *Server) Methods() []string

Methods is the log of client methods, as "conn/channel name".

func (*Server) NackPublishes

func (s *Server) NackPublishes(on bool)

NackPublishes makes publisher confirms nack instead of ack.

func (*Server) OpenConns

func (s *Server) OpenConns() int

OpenConns is how many connections are still open.

func (*Server) PeakUnacked

func (s *Server) PeakUnacked(name string) int

PeakUnacked is the most unacked messages this queue has had at once.

func (*Server) Published

func (s *Server) Published() []Pub

Published is every basic.publish, in arrival order.

func (*Server) Push

func (s *Server) Push(queue, messageID, body string) bool

Push puts a message on a queue and delivers it if a consumer is waiting. Tests use it for a message the caller did not publish.

func (*Server) Queues

func (s *Server) Queues() []string

Queues lists queue names.

func (*Server) RefuseConnections

func (s *Server) RefuseConnections(on bool)

RefuseConnections closes each accepted socket before the handshake.

func (*Server) StallOn

func (s *Server) StallOn(method string)

StallOn reads the named method and never answers it.

func (*Server) URL

func (s *Server) URL() string

URL is amqp://127.0.0.1:port, or amqps:// for StartTLS.

func (*Server) Unacked

func (s *Server) Unacked(name string) int

Unacked is how many delivered messages of this queue are not yet acked.

func (*Server) Unblock

func (s *Server) Unblock()

Unblock sends connection.unblocked to every open connection.

Jump to

Keyboard shortcuts

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