nsqio / go-nsq

The official Go package for NSQ
MIT License
2.59k stars 444 forks source link

Use the official example to create producer error reports #288

Closed zhoushuguang closed 4 years ago

zhoushuguang commented 4 years ago
package main

import (
    "github.com/nsqio/go-nsq"
)

func main() {
    config := nsq.NewConfig()

    producer, err := nsq.NewProducer("127.0.0.1:4150", config)
    if err != nil {
        panic(err)
    }
    messageBody := []byte("hello")
    topicName := "ZSG-T"

    if err = producer.Publish(topicName, messageBody); err != nil {
        panic(err)
    }

    producer.Stop()

}

run the code

go run main.go
2020/03/15 22:53:58 INF    1 (127.0.0.1:4150) connecting to nsqd
2020/03/15 22:53:58 INF    1 stopping
2020/03/15 22:53:58 INF    1 exiting router
2020/03/15 22:53:58 INF    1 (127.0.0.1:4150) beginning close
zhoushuguang commented 4 years ago

Use the latest version 1.0.8

zhoushuguang commented 4 years ago
[nsqd] 2020/03/15 23:00:32.128869 INFO: TCP: new client(127.0.0.1:54444)
[nsqd] 2020/03/15 23:00:32.128895 INFO: CLIENT(127.0.0.1:54444): desired protocol magic '  V2'
[nsqd] 2020/03/15 23:00:32.129194 INFO: [127.0.0.1:54444] IDENTIFY: {ClientID:zhoushuangde Hostname:zhoushuang HeartbeatInterval:30000 OutputBufferSize:16384 OutputBufferTimeout:250 FeatureNegotiation:true TLSv1:false Deflate:false DeflateLevel:6 Snappy:false SampleRate:0 UserAgent:go-nsq/1.0.8 MsgTimeout:0}
[nsqd] 2020/03/15 23:00:32.130378 INFO: PROTOCOL(V2): [127.0.0.1:54444] exiting ioloop
[nsqd] 2020/03/15 23:00:32.130413 INFO: PROTOCOL(V2): [127.0.0.1:54444] exiting messagePump
ploxiln commented 4 years ago

Please use "fenced code blocks" for both code samples and terminal or log output, see https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks

I don't see errors in what you pasted, I see typical logging output.

Maybe you want to set the logging level so that only warnings and errors are logged? Something like:

producer, err := nsq.NewProducer("127.0.0.1:4150", config)
if err != nil {
    panic(err)
}
producer.SetLogger(log.New(os.Stderr, "", log.Flags()), nsq.LogLevelWarning)
zhoushuguang commented 4 years ago

@ploxiln thanks, I misunderstood