Categorygithub.com/albertwidi/gonsq
modulepackage
0.0.0-20200720041452-e2ed9984c3aa
Repository: https://github.com/albertwidi/gonsq.git
Documentation: pkg.go.dev

# README

Gonsq

Work In Progress

Gonsq is a wrapper of go-nsq library.

This library is inspired by how Lyft Building an Adaptive, Multi-Tenant Stream Bus with Kafka and Golang and Flow Control architecture in envoy proxy.

Nsqio

Gonsq is not using standard nsq.Consumer and nsq.Producer, instead the library provides NSQConsumer and NSQProducer object to communicate directly with nsq.Consumer and nsq.Producer.

Some properties also added to the NSQConsumer object, for example concurrency. The concurrency information is used to inform the Gonsq about how many concurrent consumers that a given NSQConsumer want to run.

Design

Gonsq implements its own flow control on top of go-nsq library by using buffered channel. The messages that delivered to buffered channels, then consumed by internal gonsq-handler` which run using goroutines. This mechanism gives gonsq a way to communicate with each concurrent handlers to be able to control the queue flow.

gonsq-design

Stats

The library is exposing some metrics for internal usage and might be useful for the user to send the metrics to some monitoring backend. The stats object is available through nsq.Message struct and passed to the message handler.

The exposed metrics are:

  • Total Message Count: The total count of messages consumed by particular worker of topic and channel.
  • Total Error Count: The total count of error happens in particular worker of topic and channel.
  • Total Message In Buffer Count: The total count of buffer used in particular worker of topic and channel. This stat is used to determine whether a throttling mechanism need to be triggered or not.
  • Total Buffer Length: The total length of buffer available for particular worker of topic and channel
  • Total Concurrency: The total number of concurrency/woker for particular worker of topic and channel
  • Total Worker Count: The current total number of worker for particular worker of topic and channel. This stat will be useful if we have a mechanism to reduce/increase the number of worker based on condition. For now, this is used to determine the number of worker on startup and shutdown.
  • Throttled: The status of particular topic and channel, is the consumer is being throttled or not.

How To Use The Library

To use this library, the consumer must be created using nsq/nsqio.

TODO

  • DNS: make it possible to specify a single addresss with host or single/multiple address with IP. If a single host is given, then resolve to host.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

ManageConsumers creates a new ConsumerManager.
ManageProducers is a function to wrap the nsq producer.
NewConsumer for nsq.
NewConsumerManager create a new manager for NSQs consumers.
NewProducer return a new producer.

# Variables

ErrInvalidConcurrencyConfiguration happens when concurrency configuration number is not as expected.
ErrLookupdsAddrEmpty happens when NSQ lookupd address is empty when wrapping consumers.
ErrStopDeadlineExceeded heppens when stop time exceeds context deadline time.
ErrTopicWithChannelNotFound for error when channel and topic is not found.

# Structs

CompressionConfig to support compression.
ConcurrencyConfig control the concurrency flow in gonsq.
Config of nsqio.
ConsumerManager manage the consumer flow control.
ConsumerManagerOptions is a set of options for consumer manager.
LookupdConfig for lookupd configuration.
Message for nsq.
NSQConsumer backend.
NSQConsumerConfig for nsq consumer.
NSQProducer backend.
ProducerConfig struct.
ProducerManager manage the producer flow.
QueueConfig for message configuration.
Stats object to be included in every nsq consumer worker to collect statuses of nsq consumers.
TimeoutConfig for timeout configuration.

# Interfaces

ConsumerClient is he consumer client of NSQ.
Handler handle messages from NSQD and pass the message into the message handler via channel.
ProducerClient is the producer client of NSQ.

# Type aliases

HandlerFunc for nsq.
MiddlewareFunc for nsq middleware.
ThrottleStats is the indicator of throttling.