pmq

package
v0.0.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultConfigGroup = "RabbitMQ"

Variables

View Source
var PMQContextKey = _PMQContextKey{}

Functions

func InitMQByConfig

func InitMQByConfig() error

func MustInitMQByConfig

func MustInitMQByConfig()

Types

type AmqpClient

type AmqpClient struct {
	// contains filtered or unexported fields
}
var DefaultClient *AmqpClient

func NewMQ

func NewMQ(host, port, userName, password, vhost string) (*AmqpClient, error)

func (*AmqpClient) Close

func (cli *AmqpClient) Close()

func (*AmqpClient) DeclareConsumeFunc

func (cli *AmqpClient) DeclareConsumeFunc(
	exchange string, exchangeType string,
	route string, queue string,
	newWorker bool,
	cb func(ctx context.Context) error,
) error

声明一个消费者处理函数,这是多个封装中,功能最齐全的注册方法: 1:exchange为空则定义队列direct绑定到默认交换机 2:newWorker为true则启用专用单线程处理队列中的请求,否则使用公共的worker 3:callBack为处理函数,支持的形式见ParseMsgAndExecRpcCallBack的备注

func (*AmqpClient) DeclareServerEvent

func (cli *AmqpClient) DeclareServerEvent(
	exchange, route string, newWorker bool, cb func(ctx context.Context) error,
) error

内部事件:队列名为执行文件名+函数名,保证多个服务可以同时监听同一个事件

func (*AmqpClient) DeclareSimpleEvent

func (cli *AmqpClient) DeclareSimpleEvent(cb func(ctx context.Context) error) error

简单事件,函数名和事件结构体名相同,topic绑定到“默认事件交换机”DefaultNotifyExchange

func (*AmqpClient) DeclareSimpleEventPrivateWorker

func (cli *AmqpClient) DeclareSimpleEventPrivateWorker(cb func(ctx context.Context) error) error

func (*AmqpClient) DeclareSimpleRpc

func (cli *AmqpClient) DeclareSimpleRpc(cb func(ctx context.Context) error) error

RPC:用函数名作为队列名,direct绑定到默认交换机

func (*AmqpClient) GetDefaultEventExchange

func (cli *AmqpClient) GetDefaultEventExchange() string

func (*AmqpClient) GetQueueLen

func (cli *AmqpClient) GetQueueLen(rpcName string) (int, error)

--------------------------------------------------

func (*AmqpClient) PauseConsumption

func (cli *AmqpClient) PauseConsumption(rpcName string) error

func (*AmqpClient) ResumeConsumption

func (cli *AmqpClient) ResumeConsumption(rpcName string) error

func (*AmqpClient) RpcCall

func (cli *AmqpClient) RpcCall(ctx context.Context, queue string,
	reqPB protoreflect.ProtoMessage, respPB protoreflect.ProtoMessage,
) error

--------------------------------------------------

func (*AmqpClient) RpcCallStr

func (cli *AmqpClient) RpcCallStr(ctx context.Context, queue string,
	req, resp *string,
) error

func (*AmqpClient) SendServerEvent

func (cli *AmqpClient) SendServerEvent(ctx context.Context,
	exchange, route string, request protoreflect.ProtoMessage) error

func (*AmqpClient) SendServerEventStr

func (cli *AmqpClient) SendServerEventStr(ctx context.Context,
	exchange, route string, request *string) error

func (*AmqpClient) SendSimpleEvent

func (cli *AmqpClient) SendSimpleEvent(ctx context.Context,
	msg protoreflect.ProtoMessage) error

func (*AmqpClient) SetBeforeCall

func (cli *AmqpClient) SetBeforeCall(f func(ctx context.Context) error)

流程上,一个消息被调用处理函数之前,注册到这里的函数将被调用,用于: 1:编写框架性代码,如框架性数据结构的封包和解包; 2:公共的业务代码,如接口权限控制。 该方法如果返回错误,则消息处理函数不会被调用,直接返回resp给调用方。

func (*AmqpClient) Wait

func (cli *AmqpClient) Wait()

type PMQContext

type PMQContext struct {
	Req  string
	Resp string
	// contains filtered or unexported fields
}

--------------------------------------------------

func GetPMQContext added in v0.0.6

func GetPMQContext(ctx context.Context) *PMQContext

Jump to

Keyboard shortcuts

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