Documentation
¶
Index ¶
- Constants
- Variables
- func RandomAround(min, max int64) (int64, error)
- func RandomNum(length int) string
- type ChannelQueue
- type ConsumeReceive
- type Node
- type RabbitLoadBalance
- type RabbitMqData
- type RabbitMqError
- type RabbitPool
- func (r *RabbitPool) Close()
- func (r *RabbitPool) Connect(host string, port int, user string, password string) error
- func (r *RabbitPool) ConnectVirtualHost(host string, port int, user string, password string, virtualHost string) error
- func (r *RabbitPool) GetHost() string
- func (r *RabbitPool) GetPort() int
- func (r *RabbitPool) Push(data *RabbitMqData) *RabbitMqError
- func (r *RabbitPool) PushQueue(data *RabbitMqData) *RabbitMqError
- func (r *RabbitPool) RegisterConsumeReceive(consumeReceive *ConsumeReceive)
- func (r *RabbitPool) RunConsume() error
- func (r *RabbitPool) SetConnectionBalance(balance int)
- func (r *RabbitPool) SetMaxConnection(maxConnection int32)
- func (r *RabbitPool) SetMaxConsumeChannel(maxConsume int32)
- func (r *RabbitPool) SetRandomRetryTime(min, max int64)
- type RetryClientInterface
- type RetryTool
- type RetryToolInterface
Constants ¶
View Source
const ( DEFAULT_MAX_CONNECTION = 5 //rabbitmq tcp 最大连接数 DEFAULT_MAX_CONSUME_CHANNEL = 25 //最大消费channel数(一般指消费者) 轮询也是按照channel来计算的,如果有25个channel那么就得消费25个消息之后才能轮到下一个节点。因此建议设置小一点。 DEFAULT_PUSH_MAX_TIME = 5 //最大重发次数 //轮循-连接池负载算法 LOAD_BALANCE_ROUND = 1 )
View Source
const ( RABBITMQ_TYPE_PUBLISH = 1 //生产者 RABBITMQ_TYPE_CONSUME = 2 //消费者 DEFAULT_RETRY_MIN_RANDOM_TIME = 5000 //最小重试时间机数 DEFAULT_RETRY_MAX_RADNOM_TIME = 15000 //最大重试时间机数 )
View Source
const ( EXCHANGE_TYPE_FANOUT = "fanout" // Fanout:广播,将消息交给所有绑定到交换机的队列 EXCHANGE_TYPE_DIRECT = "direct" //Direct:定向,把消息交给符合指定routing key 的队列 EXCHANGE_TYPE_TOPIC = "topic" //Topic:通配符,把消息交给符合routing pattern(路由模式) 的队列 )
View Source
const ( RCODE_PUSH_MAX_ERROR = 501 //发送超过最大重试次数 RCODE_GET_CHANNEL_ERROR = 502 //获取信道失败 RCODE_CHANNEL_QUEUE_EXCHANGE_BIND_ERROR = 503 //交换机/队列/绑定失败 RCODE_CONNECTION_ERROR = 504 //连接失败 RCODE_PUSH_ERROR = 505 //消息推送失败 RCODE_CHANNEL_CREATE_ERROR = 506 //信道创建失败 RCODE_RETRY_MAX_ERROR = 507 //超过最大重试次数 ACTIVE_CLOSE_CONNECTION_ERROR = 514 // 主动关闭连接 )
* 错误码
Variables ¶
View Source
var (
ACK_DATA_NIL = errors.New("ack data nil")
)
View Source
var CONSUMER_RETRY_INTERVAL = []int{3, 15, 30, 1 * 60, 2 * 60, 5 * 60, 10 * 60, 30 * 60, 1 * 60 * 60, 3 * 60 * 60, 12 * 60 * 60, 24 * 60 * 60, 48 * 60 * 60} //消费者重试间隔
Functions ¶
func RandomAround ¶
Types ¶
type ChannelQueue ¶
type ChannelQueue struct {
// contains filtered or unexported fields
}
func NewChannelQueue ¶
func NewChannelQueue() *ChannelQueue
func (*ChannelQueue) Add ¶
func (q *ChannelQueue) Add(data *rChannel)
func (*ChannelQueue) Count ¶
func (q *ChannelQueue) Count() int32
func (*ChannelQueue) Pop ¶
func (q *ChannelQueue) Pop() (*rChannel, bool)
type ConsumeReceive ¶
type ConsumeReceive struct { ExchangeName string //交换机 ExchangeType string //交换机类型 Route string //路由 QueueName string //队列名称 EventSuccess func(data []byte, header map[string]interface{}, retryClient RetryClientInterface) bool //成功事件回调 EventFail func(int, error, []byte) //失败回调 IsDurable bool // 持久化队列 IsAutoDelete bool // 队列自动删除 IsTry bool //是否重试,会注册死信队列 MaxReTry int32 //最大重式次数 IsAutoAck bool //是否自动确认 }
* 消费者注册接收数据
type RabbitLoadBalance ¶
type RabbitLoadBalance struct { }
* 连接负载处理
func NewRabbitLoadBalance ¶
func NewRabbitLoadBalance() *RabbitLoadBalance
func (*RabbitLoadBalance) RoundRobin ¶
func (r *RabbitLoadBalance) RoundRobin(cIndex, max int32) int32
* 负载均衡 轮循
type RabbitMqData ¶
type RabbitMqData struct { ExchangeName string //交换机名称 ExchangeType string //交换机类型 见RabbitmqPool.go 常量 QueueName string //队列名称 Route string //路由 Data string //发送数据 }
* 发送数据 消息发送
func GetRabbitMqDataFormat ¶
func GetRabbitMqDataFormat(exChangeName string, exChangeType string, queueName string, route string, data string) *RabbitMqData
* 获取发送数据模板 @param exChangeName 交换机名称 @param exChangeType 交换机类型 @param queueName string 队列名称 @param route string 路由 @param data string 发送的数据
func GetRabbitMqDataFormatExpire ¶
func GetRabbitMqDataFormatExpire(exChangeName string, exChangeType string, queueName string, route string, data string) *RabbitMqData
* 获取发送数据模板 过期设置(死信队列) @param exChangeName 交换机名称 @param exChangeType 交换机类型 @param queueName string 队列名称 @param route string 路由 @param data string 发送的数据
type RabbitMqError ¶
* 错误返回
func NewRabbitMqError ¶
func NewRabbitMqError(code int, message string, detail string) *RabbitMqError
func ReconnectAndPush ¶
func ReconnectAndPush(pool *RabbitPool, data *RabbitMqData, sendTime int) *RabbitMqError
ReconnectAndPush 重连并且发送消息
func ReconnectAndPushQueue ¶
func ReconnectAndPushQueue(pool *RabbitPool, data *RabbitMqData, sendTime int) *RabbitMqError
* 发送消息
func (RabbitMqError) Error ¶
func (e RabbitMqError) Error() string
type RabbitPool ¶
type RabbitPool struct { SendFailListener func(a amqp.Return) // 发送失败的监听处理函数 // contains filtered or unexported fields }
func (*RabbitPool) Connect ¶
* 连接rabbitmq @param host string 服务器地址 @param port int 服务端口 @param user string 用户名 @param password 密码
func (*RabbitPool) ConnectVirtualHost ¶
func (r *RabbitPool) ConnectVirtualHost(host string, port int, user string, password string, virtualHost string) error
* 自定义虚拟机连接 @param host string 服务器地址 @param port int 服务端口 @param user string 用户名 @param password 密码 @param virtualHost虚拟机路径
func (*RabbitPool) GetHost ¶
func (r *RabbitPool) GetHost() string
func (*RabbitPool) GetPort ¶
func (r *RabbitPool) GetPort() int
func (*RabbitPool) PushQueue ¶
func (r *RabbitPool) PushQueue(data *RabbitMqData) *RabbitMqError
* 发送消息
func (*RabbitPool) RegisterConsumeReceive ¶
func (r *RabbitPool) RegisterConsumeReceive(consumeReceive *ConsumeReceive)
* 注册消费接收
func (*RabbitPool) SetConnectionBalance ¶
func (r *RabbitPool) SetConnectionBalance(balance int)
* 设置连接池负载算法 默认轮循
func (*RabbitPool) SetMaxConnection ¶
func (r *RabbitPool) SetMaxConnection(maxConnection int32)
* 设置最大连接数
func (*RabbitPool) SetMaxConsumeChannel ¶
func (r *RabbitPool) SetMaxConsumeChannel(maxConsume int32)
* 设置消费者最大信道数
func (*RabbitPool) SetRandomRetryTime ¶
func (r *RabbitPool) SetRandomRetryTime(min, max int64)
* 设置随时重试时间 避免同一时刻一次重试过多
type RetryClientInterface ¶
type RetryClientInterface interface { Push(pushData []byte) *RabbitMqError Ack() error }
type RetryToolInterface ¶
type RetryToolInterface interface {
// contains filtered or unexported methods
}
Click to show internal directories.
Click to hide internal directories.