Documentation
¶
Index ¶
- Constants
- Variables
- type Bus
- func (b *Bus) CallAndClose(queue string, funcName string, req any, closure func(any), ...) error
- func (b *Bus) CallAndWait(queue string, funcName string, req any, timeout time.Duration, ...) (*Message, error)
- func (b *Bus) CallAsync(queue string, funcName string, req any, ttl time.Duration) error
- func (b *Bus) CancelMsg(msg Message, callbackQueue string) error
- func (b *Bus) Connect() error
- func (b *Bus) Consume(consumers *sync.WaitGroup, queue string)
- func (b *Bus) HandlerFuncs() map[string][]string
- func (b *Bus) OpenInChannel(queue string, prefetchCount int) error
- func (b *Bus) Publish(msg *Message) error
- func (b *Bus) PublishAndClose(msg *Message, userClosure func(any), requestCtxs ...context.Context)
- func (b *Bus) RegisterAsyncHandleFunc(o HandleFuncOpts)
- func (b *Bus) RegisterHandler(opts HandlerOpts) error
- func (b *Bus) Run()
- type CustomResponse
- type HandleFuncOpts
- type Handler
- type HandlerFunc
- type HandlerOpts
- type Message
- type NilHandler
- type Opts
- type RMQPublishing
- type Response
Constants ¶
View Source
const MsgTypeCtxCancel = "CtxCancel"
View Source
const MsgTypeRequest = "Request"
View Source
const MsgTypeResponse = "Response"
View Source
const NoPrefetchSuffix = ":noprefetch" // special queue for bypassing Prefetch, ie for interrupts
Variables ¶
View Source
var ErrPublishing = errors.New("publish failed")
View Source
var ErrReplyTimeout = errors.New("bus reply timeout")
View Source
var ErrRequestCancelled = errors.New("request cancelled")
View Source
var MessageTypeError = "error"
View Source
var Slog *slog.Logger = slog.New(&NilHandler{})
Functions ¶
This section is empty.
Types ¶
type Bus ¶
type Bus struct {
AppCtx context.Context
context.Context
context.CancelFunc
DSN string
// replies
CallbackQueue string // where to listen for replies
Prefetch int // replies consuming Prefetch
MsgTTL time.Duration // TTL for replies sent to producer
// incoming
InConn *amqp091.Connection
// contains filtered or unexported fields
}
func (*Bus) CallAndClose ¶
func (*Bus) CallAndWait ¶
func (*Bus) HandlerFuncs ¶
func (*Bus) Publish ¶
Publish pushes msg to bus. Useful if RPCs are one-way, or you want to handle replies yourself
func (*Bus) PublishAndClose ¶
PublishAndClose extends Publish by catching replies + handing bus timeouts / request cancels
func (*Bus) RegisterAsyncHandleFunc ¶
func (b *Bus) RegisterAsyncHandleFunc(o HandleFuncOpts)
RegisterAsyncHandleFunc registers 1 func to handle msgs from 1 queue
func (*Bus) RegisterHandler ¶
func (b *Bus) RegisterHandler(opts HandlerOpts) error
RegisterHandler registers 1 handler (with many funcs) to handle msgs from 1 queue
type CustomResponse ¶
CustomResponse allows use to customize bus.Response reply
type HandleFuncOpts ¶
type Handler ¶
type Handler map[string]HandlerFunc
type HandlerFunc ¶
type HandlerOpts ¶
type Message ¶
type Message struct {
BusMsgType string // [Request, Response, CtxCancel]
ToQueue string // remote.worker.queue
ToFunc string // RemoteFunc
ReplyTo string // api:callback
MsgID string // msg uuid
MsgDeadline time.Time // used to build/cancel req ctx, ie RemoteFunc(ctx context.Context)
MsgTTL time.Duration // time msg lives in RMQ before dying
StatusCode int // HTTP StatusCode: 200, etc
Header http.Header // HTTP Headers: [MyHeader: foobar, ...]
Type string // pretty print StructName or CustomResponse{Type:___} string
Body []byte // raw bytes, or marshalled struct
// contains filtered or unexported fields
}
func (*Message) FromDelivery ¶
func (*Message) ToPublishing ¶
func (m *Message) ToPublishing() *amqp091.Publishing
type NilHandler ¶
type RMQPublishing ¶
type RMQPublishing struct {
// rmq vars
DeliveryMode uint8 // Transient (0 or 1) or Persistent (2)
Expiration string
// bus vars
Type string // [Request, Response, CtxCancel]
MessageId string // MsgID
CorrelationId string // ToFuncName
ReplyTo string // reply queue
ContentEncoding string // RFC3339Nano MsgTimeout for deadlines
// request & replies
Headers amqp091.Table // map[string]any{nil,bool,byte,int,float,[]byte,Decimal,time.Time}; t.SetClientConnectionName() => t["connection_name"]=connName
Body []byte // raw bytes
ContentType string // StructName (for replies)
AppId string // http status code (for replies)
// not used
Priority uint8 // 0 to 9
Timestamp time.Time // truncated to 1s
UserId string // creating user id - ex: "guest"
}
RMQPublishing for reference only
Click to show internal directories.
Click to hide internal directories.