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(ctx 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(ctx 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.
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
|
|
Src: