# README
go-nsq
The official Go package for NSQ.
Docs
See godoc and the main repo apps directory for examples of clients built using this package.
Tests
Tests are run via ./test.sh
(which requires nsqd
and nsqlookupd
to be installed).
# Functions
Auth sends credentials for authentication
After `Identify`, this is usually the first message sent, if auth is used.
DecodeMessage deserializes data (as []byte) and creates a new Message message format: [x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x]..
DeferredPublish creates a new Command to write a message to a given topic where the message will queue at the channel level until the timeout expires.
Finish creates a new Command to indiciate that a given message (by id) has been processed successfully.
Identify creates a new Command to provide information about the client.
IsValidChannelName checks a channel name for correctness.
IsValidTopicName checks a topic name for correctness.
MultiPublish creates a new Command to write more than one message to a given topic (useful for high-throughput situations to avoid roundtrips and saturate the pipe).
NewConfig returns a new default nsq configuration.
NewConn returns a new Conn instance.
NewConsumer creates a new instance of Consumer for the specified topic/channel
The only valid way to create a Config is via NewConfig, using a struct literal will panic.
NewMessage creates a Message, initializes some metadata, and returns a pointer.
NewProducer returns an instance of Producer for the specified address
The only valid way to create a Config is via NewConfig, using a struct literal will panic.
Nop creates a new Command that has no effect server side.
Ping creates a new Command to keep-alive the state of all the announced topic/channels for a given client.
Publish creates a new Command to write a message to a given topic.
ReadResponse is a client-side utility function to read from the supplied Reader according to the NSQ protocol spec:
[x][x][x][x][x][x][x][x]..
ReadUnpackedResponse reads and parses data from the underlying TCP connection according to the NSQ TCP protocol spec and returns the frameType, data or error.
Ready creates a new Command to specify the number of messages a client is willing to receive.
Register creates a new Command to add a topic/channel for the connected nsqd.
Requeue creates a new Command to indicate that a given message (by id) should be requeued after the given delay NOTE: a delay of 0 indicates immediate requeue.
StartClose creates a new Command to indicate that the client would like to start a close cycle.
Subscribe creates a new Command to subscribe to the given topic/channel.
Touch creates a new Command to reset the timeout for a given message (by id).
UnpackResponse is a client-side utility function that unpacks serialized data according to NSQ protocol spec:
[x][x][x][x][x][x][x][x]..
UnRegister creates a new Command to remove a topic/channel for the connected nsqd.
# Constants
frame types.
frame types.
frame types.
Log levels.
Log levels.
Log levels.
Log levels.
The number of bytes for a Message.ID.
states.
states.
states.
VERSION.
# Variables
ErrAlreadyConnected is returned from ConnectToNSQD when already connected.
ErrClosing is returned when a connection is closing.
ErrNotConnected is returned when a publish command is made against a Producer that is not connected.
ErrOverMaxInFlight is returned from Consumer if over max-in-flight.
ErrStopped is returned when a publish command is made against a Producer that has been stopped.
MagicV1 is the initial identifier sent when connecting for V1 clients.
MagicV2 is the initial identifier sent when connecting for V2 clients.
# Structs
AuthResponse represents the metadata returned from an AUTH command to nsqd.
Command represents a command from a client to an NSQ daemon.
Config is a struct of NSQ options
The only valid way to create a Config is via NewConfig, using a struct literal will panic.
ConfigFlag wraps a Config and implements the flag.Value interface.
Conn represents a connection to nsqd
Conn exposes a set of callbacks for the various events that occur on a connection.
Consumer is a high-level type to consume from NSQ.
ConsumerStats represents a snapshot of the state of a Consumer's connections and the messages it has seen.
ErrIdentify is returned from Conn as part of the IDENTIFY handshake.
ErrProtocol is returned from Producer when encountering an NSQ protocol level error.
ExponentialStrategy implements an exponential backoff strategy (default).
FullJitterStrategy implements http://www.awsarchitectureblog.com/2015/03/backoff.html.
IdentifyResponse represents the metadata returned from an IDENTIFY command to nsqd.
Message is the fundamental data type containing the id, body, and metadata.
Producer is a high-level type to publish to NSQ.
ProducerTransaction is returned by the async publish methods to retrieve metadata about the command after the response is received.
# Interfaces
BackoffStrategy defines a strategy for calculating the duration of time a consumer should backoff for a given attempt.
ConnDelegate is an interface of methods that are used as callbacks in Conn.
A Dialer is a means to establish a connection.
DiscoveryFilter is an interface accepted by `SetBehaviorDelegate()` for filtering the nsqds returned from discovery via nsqlookupd.
FailedMessageLogger is an interface that can be implemented by handlers that wish to receive a callback when a message is deemed "failed" (i.e.
Handler is the message processing interface for Consumer
Implement this interface for handlers that return whether or not message processing completed successfully.
MessageDelegate is an interface of methods that are used as callbacks in Message.
# Type aliases
HandlerFunc is a convenience type to avoid having to declare a struct to implement the Handler interface, it can be used like this:
consumer.AddHandler(nsq.HandlerFunc(func(m *Message) error { // handle the message })).
LogLevel specifies the severity of a given log message.
MessageID is the ASCII encoded hexadecimal message ID.