Documentation
ยถ
Index ยถ
Constants ยถ
This section is empty.
Variables ยถ
var ( // JSONEncoder is an implementation of the EncoderFn interface // that encodes a Message into JSON format. JSONEncoder EncoderFn = func(_ context.Context, m interfaces.Message) (data []byte, err error) { return json.Marshal(m) } // JSONDecoder is a DecoderFn implementation that decodes JSON data into a Message. JSONDecoder DecoderFn = func(_ context.Context, data []byte) (m interfaces.Message, err error) { err = json.Unmarshal(data, &m) return } DefaultEncoder EncoderFn = JSONEncoder DefaultDecoder DecoderFn = JSONDecoder )
var ( // JSONEncoding represents the encoding configuration for JSON. JSONEncoding = &Encoding{ ContentType: headerVal.ContentTypeJSON, Encode: JSONEncoder, Decode: JSONDecoder, } DefaultEncoding = JSONEncoding )
Functions ยถ
func AddGoQueueEncoding ยถ
func AddGoQueueEncoding(contentType headerVal.ContentType, encoding *Encoding)
AddGoQueueEncoding stores the given encoding for the specified content type in the goQueueEncodingMap. The goQueueEncodingMap is a concurrent-safe map that maps content types to encodings. The content type is specified by the `contentType` parameter, and the encoding is specified by the `encoding` parameter. This function is typically used to register custom encodings for specific content types in the GoQueue library.
func SetupLogging ยถ
func SetupLogging()
SetupLogging configures zerolog with sensible defaults for goqueue. This is automatically called when importing consumer or publisher packages, but can be called explicitly for custom configuration.
Note: This function is safe to call multiple times.
func SetupLoggingWithDefaults ยถ
func SetupLoggingWithDefaults()
SetupLoggingWithDefaults configures zerolog and sets up a default global logger with console output and reasonable formatting for development. This is useful for development environments or when you want pretty-printed logs.
Types ยถ
type DecoderFn ยถ
DecoderFn is a function type that decodes a byte slice into a Message. It takes a context and a byte slice as input and returns a Message and an error.
type EncoderFn ยถ
EncoderFn is a function type that encodes a message into a byte slice. It takes a context and a message as input and returns the encoded data and an error (if any).
type Encoding ยถ
type Encoding struct { ContentType headerVal.ContentType // The content type associated with this encoding. Encode EncoderFn // The encoding function used to encode data. Decode DecoderFn // The decoding function used to decode data. }
Encoding represents an encoding configuration for a specific content type.
func GetGoQueueEncoding ยถ
func GetGoQueueEncoding(contentType headerVal.ContentType) (res *Encoding, ok bool)
GetGoQueueEncoding returns the encoding associated with the given content type. It looks up the encoding in the goQueueEncodingMap and returns it along with a boolean value indicating if the encoding was found. If the encoding is not found, it returns nil and false.
type QueueService ยถ
type QueueService struct { NumberOfConsumer int // The number of consumers to process messages concurrently. // contains filtered or unexported fields }
QueueService represents a service that handles message queuing operations.
func NewQueueService ยถ
func NewQueueService(opts ...options.GoQueueOptionFunc) *QueueService
NewQueueService creates a new instance of QueueService with the provided options. It accepts a variadic parameter `opts` which allows configuring the QueueService. The options are applied in the order they are provided. Returns a pointer to the created QueueService.
func (*QueueService) Publish ยถ
func (qs *QueueService) Publish(ctx context.Context, m interfaces.Message) (err error)
Publish publishes a message to the queue. It returns an error if the publisher is not defined or if there was an error while publishing the message.
func (*QueueService) Start ยถ
func (qs *QueueService) Start(ctx context.Context) (err error)
Start starts the queue service by spawning multiple consumers to process messages. It returns an error if the consumer or handler is not defined. The method uses the provided context to manage the lifecycle of the consumers.
Directories
ยถ
Path | Synopsis |
---|---|
examples
|
|
rabbitmq/basic
command
|
|
rabbitmq/withretries
command
|
|
headers
|
|
internal
|
|