### Documentation and Examples in go-nsq Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md This entry highlights documentation updates and improvements to code examples within the go-nsq project, including fixes for descriptions and the addition of signal handling examples. ```go // go-nsq change log entries for documentation and examples // #294 - docs: fix producer example (thanks @nikitabuyevich) // #307 - docs: add exit signal handling to consumer example // #324 - docs: fix Consumer.SetLogger() description (thanks @gabriel-vasile) // #271 - godoc for publisher and consumer (thanks @skateinmars) ``` -------------------------------- ### Create and Configure nsq.Config Source: https://github.com/nsqio/go-nsq/blob/master/UPGRADING.md Demonstrates how to create a new nsq.Config and set configuration options using the `Set` method. This approach allows for flexible configuration, especially when reading from external sources. ```Go cfg := nsq.NewConfig() cfg.Set("nsqd_tcp_address", "127.0.0.1:4150") cfg.Set("max_in_flight", 10) // Further configuration or validation can be done here // cfg.Validate() ``` -------------------------------- ### Implement nsq.Handler with HandlerFunc Source: https://github.com/nsqio/go-nsq/blob/master/UPGRADING.md Demonstrates how to use nsq.HandlerFunc to simplify implementing the nsq.Handler interface for basic message processing. This approach is suitable for straightforward tasks where asynchronous handling is not required. ```go r, err := nsq.NewConsumer("test_topic", "test_channel", nsq.NewConfig()) if err != nil { log.Fatalf(err.Error()) } r.AddHandler(nsq.HandlerFunc(func(m *nsq.Message) error { return doSomeWork(m) })) err := r.ConnectToNSQD(nsqdAddr) if err != nil { log.Fatalf(err.Error()) } <-r.StopChan ``` -------------------------------- ### Configure Custom Logger with Log Level Source: https://github.com/nsqio/go-nsq/blob/master/UPGRADING.md Illustrates how to set a custom logger for the Consumer or Producer using the standard Go log.Logger interface and specifying a log level. This provides flexibility in controlling logging output. ```go logger := log.New(os.Stdout, "[nsq] ", log.LstdFlags) consumer.SetLogger(logger, nsq.LogLevelInfo) ``` -------------------------------- ### Producer Publish Error Handling Source: https://github.com/nsqio/go-nsq/blob/master/UPGRADING.md Shows the simplified error handling for the Producer's Publish method. Previously, both error and frameType needed checking; now, only the returned error needs to be inspected for success or failure. ```go err := producer.Publish("topic", []byte("message")) if err != nil { log.Fatalf("Failed to publish message: %v", err) } ``` -------------------------------- ### Requeue Message Without Backoff Source: https://github.com/nsqio/go-nsq/blob/master/UPGRADING.md Demonstrates how to requeue a message without triggering the consumer's backoff mechanism. This is useful when a message needs to be retried immediately without penalizing subsequent message processing. ```go m.RequeueWithoutBackoff() ``` -------------------------------- ### Asynchronous Message Handling with nsq.Message Control Source: https://github.com/nsqio/go-nsq/blob/master/UPGRADING.md Illustrates advanced asynchronous message handling by disabling auto-response and manually managing message states. This allows for complex workflows where message acknowledgment or requeuing happens later, potentially after external processing. ```go type myHandler struct {} func (h *myHandler) HandleMessage(m *nsq.Message) error { m.DisableAutoResponse() workerChan <- m return nil } go func() { for m := range workerChan { err := doSomeWork(m) if err != nil { m.Requeue(-1) continue } m.Finish() } }() cfg := nsq.NewConfig() cfg.MaxInFlight = 1000 r, err := nsq.NewConsumer("test_topic", "test_channel", cfg) if err != nil { log.Fatalf(err.Error()) } r.AddConcurrentHandlers(&myHandler{}, 20) err := r.ConnectToNSQD(nsqdAddr) if err != nil { log.Fatalf(err.Error()) } <-r.StopChan ``` -------------------------------- ### Dependency and Build System Updates in go-nsq Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md This entry covers updates to project dependencies and the build system, including switching to GitHub Actions for CI and addressing potential snappy deadlocks. ```go // go-nsq change log entries for dependency and build system updates // #329/#330 - switch to GitHub Actions for CI // #203 - switch to golang/snappy (addressing potential snappy related deadlocks) ``` -------------------------------- ### Go-nsq: Reader Configure Method Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Adds a `Configure()` method to the `Reader` for runtime configuration. ```Go // #14 - add `Reader.Configure()` ``` -------------------------------- ### Go-nsq: Snappy/Deflate Feature Negotiation Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Implements feature negotiation for Snappy and Deflate compression. ```Go // #4 - snappy/deflate feature negotiation ``` -------------------------------- ### Go-nsq: Support 64 Character Topic/Channel Names Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Extends support to allow topic and channel names of up to 64 characters. ```Go // #36 - support 64 character topic/channel names ``` -------------------------------- ### TLS Configuration in go-nsq Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md This section covers the TLS configuration options introduced in go-nsq, including minimum version settings and certificate/key configurations. ```go // go-nsq change log entry for TLS configuration // #102 - TLS min/max config defaults (thanks @twmb) // #98 - add tls-min-version option (thanks @twmb) // #75/#77/#78 - add tls-cert and tls-key config options ``` -------------------------------- ### Logging and Configuration in go-nsq Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md This section details changes related to logging and configuration within go-nsq, including support for separate loggers per level and config initialization checks. ```go // go-nsq change log entries for logging and configuration // #275/#281 - support separate Logger for each log level (thanks @crazyweave) // #283 - remove redundant Config initialized check (thanks @SwanSpouse) // #155 - config: support `flag.Value` interface // #138 - fix lint, vet, fmt issues // #137 - remove `go-simplejson` dependency // #122 - refactor log level string handling // #108 - fix potential logger race conditions (thanks @judwhite) ``` -------------------------------- ### Go Modules Support in go-nsq Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md This entry details the integration of Go Modules support in the go-nsq library, enabling better dependency management for Go projects. ```go // go-nsq change log entry for go modules support // #248 - support go modules ``` -------------------------------- ### go-nsq go vet TLS.Config Copying Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md This entry addresses a go vet issue related to copying TLS configurations in the go-nsq library. ```go // go-nsq change log entry for go vet TLS.Config copying // #255 - go vet tls.Config copying (thanks @iaburton) ``` -------------------------------- ### go-nsq AUTHORS File and CI Updates Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md This snippet notes the addition of an AUTHORS file and the transition to GitHub Actions for Continuous Integration in the go-nsq project. ```go // go-nsq change log entries for AUTHORS file and CI updates // #297 - add AUTHORS file // #329/#330 - switch to GitHub Actions for CI ``` -------------------------------- ### Go-nsq: Per-Connection TLS Configuration Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Enables per-connection TLS configuration and setting the ServerName for secure connections to NSQ. ```Go // #54 - per-connection TLS config and set `ServerName` ``` -------------------------------- ### Go-nsq: Add AUTH Support Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Introduces support for the AUTH command, allowing authentication with the NSQ server. This is a significant API change. ```Go // #35 - AUTH support ``` -------------------------------- ### Producer and Consumer Enhancements in go-nsq Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md This entry summarizes various improvements made to the producer and consumer functionalities within the go-nsq library, such as connection handling, RDY count updates, and backoff strategies. ```go // go-nsq change log entries for producer and consumer enhancements // #282 - consumer: reduce duplicate RDY (ready) count updates (thanks @andyxning) // #313 - add Authorization header to lookup queries // #321 - consumer: fix panic with some invalid lookupd http addresses (thanks @martin-sucha) // #317 - producer: connect() code-style improvement (thanks @martin-sucha) // #330 - fix random backoff jitter on 32-bit architectures // #333 - consumer: re-use http client with keepalives for lookupd requests (thanks @JieTrancender) // #336 - producer: shutdown logging prefix consistent with other logging (thanks @karalabe) // #249 - consumer: update RDY when setting MaxInFlight to 0 // #267 - check response message size is positive (thanks @andyxning) // #270 - set log level (thanks @YongHaoWu) // #97/#209 - consumer: retry nsqlookupd queries // #179/#208 - consumer: redistribute RDY when connections are active // #184/#201 - producer: fix misleading Stop() EOF (thanks @mengskysama) // #202 - consumer: fix backoff logging // #175 - consumer: reduce garbage generation in DecodeMessage (thanks @Dieterbe) // #162 - producer: support `DeferredPublish` (thanks @DanielHeckrath) // #156 - consumer: prevent data race on RNG // #147/#150 - consumer: fix application of `max_backoff_duration` (thanks @judwhite) // #133 - fix `ErrNotConnected` race during `Producer` connection (thanks @jeddenlea) // #132 - fix `RDY` redistribution after backoff with no connections // #128 - fix backoff stall when using `RequeueWithoutBackoff` // #127 - fix handling of connection closing when resuming after backoff (thanks @jnewmano) // #126 - allow `BackoffStrategy` to be set via flag (thanks @twmb) // #125 - add pluggable consumer `BackoffStrategy`; add full-jitter strategy (thanks @hden) // #124 - add `DialTimeout` and `LocalAddr` config (thanks @yashkin) // #119 - add `Producer.Ping()` method (thanks @zulily) // #120 - fix `Message` data races on `responded` // #114 - fix lookupd jitter having no effect (thanks @judwhite) // #104 - fix reconnect address bug (thanks @ryanslade) // #106 - fix backoff reconnect deadlock (thanks @ryanslade) // #107 - fix out-of-bounds error when removing nsqlookupd addresses (thanks @andreas) // #111 - fix resolved address error in reconnect loop (thanks @twmb) // #99 - fix `Consumer.Stop()` race and `Producer.Stop()` deadlock (thanks @tylertreat) // #95 - cleanup panic during `Consumer.Stop()` if handlers are deadlocked // #93 - expose a way to get `Consumer` runtime stats (thanks @dcarney) // #94 - allow `#ephemeral` topic names (thanks @jamesgroat) // #89 - don't spam connection teardown cleanup messages // #91 - add consumer `DisconnectFrom*` // #87 - allow `heartbeat_interval` and `output_buffer_timeout` to be disabled // #86 - pluggable `nsqlookupd` behaviors // #83 - send `RDY` before `FIN`/`REQ` (forwards compatibility with nsqio/nsq#404) // #82 - fix panic when conn isn't assigned ``` -------------------------------- ### Go-nsq: Send IDENTIFY Command Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Ensures the IDENTIFY command is sent during connection establishment. ```Go // #127 - send IDENTIFY (missed in #90) ``` -------------------------------- ### Go-nsq: Flexible nsqlookupd URL Specification Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Provides more flexible ways to specify nsqlookupd addresses for connecting to the NSQ cluster. ```Go // #43/#63 - more flexible `nsqlookupd` URL specification ``` -------------------------------- ### Go-nsq: Add TOUCH Command Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Introduces the TOUCH command for extending message visibility. ```Go // #119 - add TOUCH command ``` -------------------------------- ### Go-nsq: Support broadcast_address Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Adds support for the `broadcast_address` option. ```Go // #177 - support `broadcast_address` ``` -------------------------------- ### Go-nsq: TLS Feature Negotiation Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Adds TLS feature negotiation for secure communication with NSQ. ```Go // #227 - TLS feature negotiation ``` -------------------------------- ### Go-nsq: User Agent String Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Introduces the ability to send a user agent string, which is displayed in nsqadmin. ```Go // #23 - user agent ``` -------------------------------- ### Go-nsq: Reader Logs Disambiguate Topic/Channel Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Improves reader logging by disambiguating topic and channel information. ```Go // #27 - reader logs disambiguate topic/channel ``` -------------------------------- ### Go-nsq: Add Writer Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Introduces the `Writer` type for publishing messages to NSQ. ```Go // #164/#202/#255 - add `Writer` ``` -------------------------------- ### Go-nsq: Channel Sampling Support Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Adds support for channel sampling, allowing selective consumption of messages. ```Go // #22 - channel sampling ``` -------------------------------- ### Go-nsq: Add Backoff to Reader Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Integrates backoff functionality into the `Reader` for handling temporary connection issues. ```Go // #16 - add backoff to Reader ``` -------------------------------- ### Go-nsq: Support --max-rdy-count Config Option Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Adds support for the `--max-rdy-count` configuration option on `nsqd`. ```Go // #175 - support for `nsqd` config option `--max-rdy-count` ``` -------------------------------- ### Go-nsq: Refactor Public API Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Significant refactoring of the public API, requiring users to consult the UPGRADING.md file for compatibility information. ```Go // #30/#38/#39/#42/#45/#46/#48/#51/#52/#65/#70 - refactor public API (see [UPGRADING](UPGRADING.md)) ``` -------------------------------- ### Go-nsq: Improved Error and Magic Handling Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Enhances the handling of errors and magic numbers during communication. ```Go // #133 - improved handling of errors/magic ``` -------------------------------- ### Go-nsq: Touch Method on Message Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Adds a `Touch()` method to the `Message` type for extending message visibility. ```Go // #6 - `Touch()` method on `Message` ``` -------------------------------- ### Go-nsq: nsqlookupd Polling Improvements Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Enhances the polling mechanism for `nsqlookupd`. ```Go // #250 - `nsqlookupd` polling improvements ``` -------------------------------- ### Go-nsq: Auto-Reconnect to Hard-coded nsqd Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Enables auto-reconnection to hard-coded `nsqd` addresses. ```Go // #169 - auto-reconnect to hard-coded `nsqd` ``` -------------------------------- ### Go-nsq: Exported Error for Configured nsqlookupd Address Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Returns an exported error when an nsqlookupd address is already configured. ```Go // #18 - return an exported error when an `nsqlookupd` address is already configured ``` -------------------------------- ### Go-nsq: Requeue Method on Message Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Adds a `Requeue()` method to the `Message` type, allowing messages to be requeued. ```Go // #12 - `Requeue()` method on `Message` ``` -------------------------------- ### Go-nsq: Ignore Publish Responses in Writer Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Provides the ability to ignore publish responses in the `Writer`. ```Go // #9 - ability to ignore publish responses in `Writer` ``` -------------------------------- ### Go-nsq: Connection Pool Goroutine Safety Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Ensures goroutine safety for the connection pool. ```Go // #161 - connection pool goroutine safety ``` -------------------------------- ### Go-nsq: MaxBackoffDuration Disables Backoff Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Setting `MaxBackoffDuration` to `0` disables the backoff mechanism. ```Go // #186 - `MaxBackoffDuration` of `0` disables backoff ``` -------------------------------- ### Go-nsq: Use Last RDY Count for IsStarved Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Utilizes the last RDY count for the `IsStarved()` calculation and redistributes RDY state. ```Go // #169 - use last RDY count for `IsStarved()`; redistribute RDY state ``` -------------------------------- ### Go-nsq: Limit IsStarved to Connections with In-flight Messages Source: https://github.com/nsqio/go-nsq/blob/master/ChangeLog.md Restricts the `IsStarved()` check to connections that have messages in flight. ```Go // #243 - limit `IsStarved()` to connections w/ in-flight messages ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.