42 lines
892 B
Go
42 lines
892 B
Go
package mq
|
|
|
|
import "context"
|
|
|
|
type MessageHandler func(ctx context.Context, body []byte)
|
|
|
|
type Consumer interface {
|
|
Consume(handler MessageHandler)
|
|
}
|
|
|
|
type Connection interface {
|
|
Connect() error
|
|
Close() error
|
|
Channel() (Channel, error)
|
|
NotifyClose(chan *Error) chan *Error
|
|
}
|
|
|
|
type Channel interface {
|
|
ExchangeDeclare(name, kind string, durable, autoDelete, internal, noWait bool, args Table) error
|
|
QueueDeclare(name string, durable, autoDelete, exclusive, noWait bool, args Table) (Queue, error)
|
|
QueueBind(name, key, exchange string, noWait bool, args Table) error
|
|
Consume(queue, consumer string, autoAck, exclusive, noLocal, noWait bool, args Table) (<-chan Delivery, error)
|
|
Close() error
|
|
}
|
|
|
|
type Queue struct {
|
|
Name string
|
|
}
|
|
|
|
type Delivery struct {
|
|
Body []byte
|
|
}
|
|
|
|
type Error struct {
|
|
Code int
|
|
Reason string
|
|
Server bool
|
|
Recover bool
|
|
}
|
|
|
|
type Table map[string]interface{}
|