Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulminator committed May 8, 2024
1 parent ef1060c commit 2510955
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
7 changes: 6 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ func (c *Conn) getLogLevel() LogLevel {

// Connect dials and bootstraps the nsqd connection
// (including IDENTIFY) and returns the IdentifyResponse
func (c *Conn) Connect(ctx context.Context) (*IdentifyResponse, error) {
func (c *Conn) Connect() (*IdentifyResponse, error) {
ctx := context.Background()
return c.ConnectWithContext(ctx)
}

func (c *Conn) ConnectWithContext(ctx context.Context) (*IdentifyResponse, error) {
dialer := &net.Dialer{
LocalAddr: c.config.LocalAddr,
Timeout: c.config.DialTimeout,
Expand Down
3 changes: 1 addition & 2 deletions consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package nsq

import (
"bytes"
"context"
"errors"
"fmt"
"log"
Expand Down Expand Up @@ -581,7 +580,7 @@ func (r *Consumer) ConnectToNSQD(addr string) error {
conn.Close()
}

resp, err := conn.Connect(context.Background())
resp, err := conn.Connect()
if err != nil {
cleanupConnection()
return err
Expand Down
5 changes: 3 additions & 2 deletions producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ type producerConn interface {
SetLogger(logger, LogLevel, string)
SetLoggerLevel(LogLevel)
SetLoggerForLevel(logger, LogLevel, string)
Connect(context.Context) (*IdentifyResponse, error)
Connect() (*IdentifyResponse, error)
ConnectWithContext(context.Context) (*IdentifyResponse, error)
Close() error
WriteCommand(*Command) error
WriteCommandWithContext(context.Context, *Command) error
Expand Down Expand Up @@ -356,7 +357,7 @@ func (w *Producer) connect(ctx context.Context) error {
w.conn.SetLoggerForLevel(w.logger[index], LogLevel(index), format)
}

_, err := w.conn.Connect(ctx)
_, err := w.conn.ConnectWithContext(ctx)
if err != nil {
w.conn.Close()
w.log(LogLevelError, "(%s) error connecting to nsqd - %s", w.addr, err)
Expand Down
7 changes: 6 additions & 1 deletion producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,12 @@ func (m *mockProducerConn) SetLoggerLevel(lvl LogLevel) {}

func (m *mockProducerConn) SetLoggerForLevel(logger logger, level LogLevel, format string) {}

func (m *mockProducerConn) Connect(ctx context.Context) (*IdentifyResponse, error) {
func (m *mockProducerConn) Connect() (*IdentifyResponse, error) {
ctx := context.Background()
return m.ConnectWithContext(ctx)
}

func (m *mockProducerConn) ConnectWithContext(ctx context.Context) (*IdentifyResponse, error) {
return &IdentifyResponse{}, nil
}

Expand Down

0 comments on commit 2510955

Please sign in to comment.