grmqt

package
v1.67.2 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 7 Imported by: 0

README

Package grmqt

Пакет grmqt предоставляет вспомогательную обёртку над RabbitMQ-клиентом для функционального тестирования с автоматическим созданием и удалением виртуального хоста, а также публикацией и получением сообщений.

Types

Client

Структура Client инкапсулирует соединение с RabbitMQ и предоставляет методы для удобной работы с очередями, публикацией сообщений и конфигурацией клиента grmqx в тестах.

Methods:

func New(t *test.Test) *Client

Создаёт новый экземпляр клиента. Создаёт виртуальный хост RabbitMQ для теста, настраивает соединение и клиент grmqx. Все ресурсы автоматически очищаются при завершении теста.

(c *Client) ConnectionConfig() grmqx.Connection

Возвращает конфигурацию соединения grmqx.Connection, используемую клиентом.

(c *Client) QueueLength(queue string) int

Возвращает количество сообщений в указанной очереди.

(c *Client) Upgrade(config grmqx.Config)

Вызывает метод Upgrade у клиента grmqx, подставляя URL из конфигурации соединения.

(c *Client) PublishJson(exchange string, routingKey string, data any)

Публикует сообщение в формате JSON в указанный обменник и routing key.

(c *Client) Publish(exchange string, routingKey string, messages ...amqp091.Publishing)

Публикует одно или несколько сообщений в указанный обменник и routing key.

(c *Client) DrainMessage(queue string) amqp091.Delivery

Получает одно сообщение из очереди. Тест завершится с ошибкой, если сообщение отсутствует.

(c *Client) useChannel(f func(ch *amqp091.Channel))

Вспомогательный метод для работы с каналом AMQP. Открывает, передаёт в функцию f, а затем закрывает канал.

Usage

Default usage flow
package mypkg_test

import (
	"testing"

	"github.com/txix-open/isp-kit/test"
	"github.com/txix-open/isp-kit/test/grpct"
)

func TestPublishAndDrain(t *testing.T) {
	testCtx := test.New(t)
	client := grmqt.New(testCtx)

	client.PublishJson("my-exchange", "my-queue", map[string]string{"hello": "world"})
	msg := client.DrainMessage("my-queue")
	testCtx.Assert().Equal("application/json", msg.ContentType)
}

Documentation

Overview

Package grmqt provides test helpers for RabbitMQ operations. It creates isolated virtual hosts for each test and automatically cleans them up after the test completes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	GrmqxCli *grmqx.Client
	// contains filtered or unexported fields
}

Client provides a test helper for RabbitMQ operations. It manages a dedicated connection and virtual host for each test.

func New

func New(t *test.Test) *Client

New creates a new RabbitMQ test client with an isolated virtual host. The virtual host is created before the test and automatically deleted when the test completes. Connection parameters can be overridden using environment variables: RMQ_HOST, RMQ_PORT, RMQ_USER, RMQ_PASS.

nolint:nosprintfhostport,noctx,bodyclose,mnd

func (*Client) ConnectionConfig

func (c *Client) ConnectionConfig() grmqx.Connection

ConnectionConfig returns the connection configuration used by the client.

func (*Client) DrainMessage

func (c *Client) DrainMessage(queue string) amqp091.Delivery

DrainMessage retrieves and returns a single message from the specified queue. Panics if no message is available.

func (*Client) Publish

func (c *Client) Publish(exchange string, routingKey string, messages ...amqp091.Publishing)

Publish publishes one or more messages to the specified exchange and routing key. Panics if publishing fails.

func (*Client) PublishJson

func (c *Client) PublishJson(exchange string, routingKey string, data any)

PublishJson publishes a JSON-encoded message to the specified exchange and routing key. Panics if JSON marshaling or publishing fails.

func (*Client) QueueLength

func (c *Client) QueueLength(queue string) int

QueueLength returns the number of messages in the specified queue.

func (*Client) Upgrade

func (c *Client) Upgrade(config grmqx.Config)

Upgrade upgrades the RabbitMQ client with the provided configuration.

Jump to

Keyboard shortcuts

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