Categorygithub.com/kgip/go-rabbit-template
modulepackage
1.0.0
Repository: https://github.com/kgip/go-rabbit-template.git
Documentation: pkg.go.dev

# README

go-rabbit-template

Wrapper of rabbitmq/amqp091-go that provides reconnection logic and sane defaults. Hit the project with a star if you find it useful ⭐

reference (https://godoc.org/github.com/wagslane/go-rabbitmq)

Motivation

Streadway's AMQP library is currently the most robust and well-supported Go client I'm aware of. It's a fantastic option and I recommend starting there and seeing if it fulfills your needs. Their project has made an effort to stay within the scope of the AMQP protocol, as such, no reconnection logic and few ease-of-use abstractions are provided.

⚙️ Installation

Inside a Go module:

go get github.com/kgip/go-rabbit-template

🚀 Quick Start Consumer

Default

template, _ := NewRabbitTemplate(url, Config{})
template.RegisterConsumer("test.rabbit_template.queue", "test.consumer1", false, false, false, false, &Qos{PrefetchCount: 2}, nil, func(delivery *Delivery) {
    fmt.Println(string(delivery.Body), delivery.DeliveryTag, "test.consumer1")
    delivery.Acknowledger.Ack(delivery.DeliveryTag, false)
})

Simple consumer

template, _ := NewRabbitTemplate(url, Config{})
template.SimpleRegisterConsumer("test.rabbit_template.queue", "test.consumer1", func(delivery *Delivery) {
    fmt.Println(string(delivery.Body), delivery.DeliveryTag, "test.consumer1")
    delivery.Acknowledger.Ack(delivery.DeliveryTag, false)
})

🚀 Quick Start Publisher

Default

template, _ := NewRabbitTemplate(url, Config{EnablePublisherConfirm: true, EnablePublisherReturns: true})
template.RegisterConfirmCallback(func(ack bool, DeliveryTag uint64, correlationData *CorrelationData) {
    fmt.Println(ack, DeliveryTag, correlationData.ID)
})
template.RegisterReturnCallback(func(r *Return) {
    fmt.Println(string(r.Body), r.ReplyText, r.RoutingKey, r.Exchange)
})
correlationData := &CorrelationData{ID: uuid.NewV4().String()}
template.Publish("test.rabbit_template.topic.exchange", "test.key", true, false, &Message{Body: []byte(fmt.Sprintf("hello~"))}, correlationData)

Simple publish

template, _ := NewRabbitTemplate(url, Config{EnablePublisherConfirm: true, EnablePublisherReturns: true})
template.RegisterConfirmCallback(func(ack bool, DeliveryTag uint64, correlationData *CorrelationData) {
    fmt.Println(ack, DeliveryTag, correlationData.ID)
})
template.RegisterReturnCallback(func(r *Return) {
    fmt.Println(string(r.Body), r.ReplyText, r.RoutingKey, r.Exchange)
})
correlationData := &CorrelationData{ID: uuid.NewV4().String()}
template.SimplePublish("test.rabbit_template.topic.exchange", "test.key", "hello~", correlationData)

Other usage examples

See the test directory for more ideas.

# Packages

No description provided by the author

# Functions

自定义日志输出时间格式.
NewChannelPool 创建一个连接池 conn amqp连接 maxChannelCount 连接池最大连接数 timeout 获取连接的.
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
Constants for standard AMQP 0-9-1 exchange types.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
ChannelPool 信道连接池.
No description provided by the author
CorrelationData 每个消息附带的额外信息.
No description provided by the author
Delivery captures the fields for a previously delivered message resident in a queue to be delivered by the server to a consumer from Channel.Consume or Channel.Get.
Message captures the client message sent to the server.
PoolChannel 连接池包装的信道.
No description provided by the author
RabbitTemplate RabbitMQ操作工具.
Return captures a flattened struct of fields returned by the server when a Publishing is unable to be delivered either due to the `mandatory` flag set and no route found, or `immediate` flag set and no free consumer.

# Interfaces

AcknowledgerAdapter notifies the server of successful or failed consumption of deliveries via identifier found in the Delivery.DeliveryTag field.
Authentication interface provides a means for different SASL authentication mechanisms to be used during connection tuning.
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author