Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go v1.1.0 #367

Open
weicaijiang opened this issue Jun 18, 2024 · 3 comments
Open

go v1.1.0 #367

weicaijiang opened this issue Jun 18, 2024 · 3 comments

Comments

@weicaijiang
Copy link

[nsqlookupd] 2024/06/18 10:16:17.921801 INFO: TCP: new client(192.168.1.128:53122)
[nsqlookupd] 2024/06/18 10:16:17.921894 INFO: CLIENT(192.168.1.128:53122): desired protocol magic ' V2'
[nsqlookupd] 2024/06/18 10:16:17.922006 ERROR: client(192.168.1.128:53122) bad protocol magic ' V2'

how to fix?

@jehiah
Copy link
Member

jehiah commented Jun 18, 2024

@weicaijiang can you share more about your configuration and steps to reproduce?

@weicaijiang
Copy link
Author

weicaijiang commented Jun 19, 2024

use nsq-1.3.0.linux-amd64.go1.21.5

logs 如下

[nsqlookupd] 2024/06/19 08:54:25.337871 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 15.00008774s)
[nsqlookupd] 2024/06/19 08:54:40.337752 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 14.999890179s)
[nsqlookupd] 2024/06/19 08:54:48.692219 INFO: TCP: new client(192.168.1.128:61467)
[nsqlookupd] 2024/06/19 08:54:48.692332 INFO: CLIENT(192.168.1.128:61467): desired protocol magic '  V2'
[nsqlookupd] 2024/06/19 08:54:48.692404 ERROR: client(192.168.1.128:61467) bad protocol magic '  V2'
[nsqlookupd] 2024/06/19 08:54:55.337647 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 14.999893212s)
[nsqlookupd] 2024/06/19 08:55:10.338122 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 15.0004761s)
[nsqlookupd] 2024/06/19 08:55:25.338283 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 15.000161573s)
[nsqlookupd] 2024/06/19 08:55:40.338043 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 14.999760969s)
[nsqlookupd] 2024/06/19 08:55:55.337735 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 14.999688862s)
[nsqlookupd] 2024/06/19 08:56:10.337742 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 15.000005623s)
[nsqlookupd] 2024/06/19 08:56:25.337761 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 15.000020562s)
[nsqlookupd] 2024/06/19 08:56:40.337796 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 15.000034803s)
[nsqlookupd] 2024/06/19 08:56:48.315472 INFO: TCP: new client(192.168.1.128:61544)
[nsqlookupd] 2024/06/19 08:56:48.315507 INFO: CLIENT(192.168.1.128:61544): desired protocol magic '  V2'
[nsqlookupd] 2024/06/19 08:56:48.315586 ERROR: client(192.168.1.128:61544) bad protocol magic '  V2'
[nsqlookupd] 2024/06/19 08:56:55.337834 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 15.000040102s)
[nsqlookupd] 2024/06/19 08:57:10.338112 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 15.000277662s)
[nsqlookupd] 2024/06/19 08:57:25.337786 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 14.999677478s)
[nsqlookupd] 2024/06/19 08:57:40.337571 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 14.999780522s)
[nsqlookupd] 2024/06/19 08:57:55.338090 INFO: CLIENT(127.0.0.1:51484): pinged (last ping 15.000523183s)

code as

// Nsq发送测试
package main

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

var producer *nsq.Producer

// 主函数
func main() {
	strIP1 := "127.0.0.1:4150"
	strIP1 = "192.168.1.138:4160"
	// strIP2 := "127.0.0.1:4152"
	InitProducer(strIP1)

	// running := true

	//读取控制台输入
	// reader := bufio.NewReader(os.Stdin)
	// if running {
		// data, _, _ := reader.ReadLine()
		command := string("你好")
		// if command == "stop" {
		// 	running = false
		// }
		err := Publish("test1", command)
		if err != nil{
			fmt.Println("err: ", err)
		}
		// for err := Publish("test", command); err != nil; err = Publish("test", command) {
		// 	//切换IP重连
		// 	strIP1, strIP2 = strIP2, strIP1
		// 	InitProducer(strIP1)
		// }
	// }
	//关闭
	producer.Stop()
}

// 初始化生产者
func InitProducer(str string) {
	var err error
	fmt.Println("address: ", str)
	producer, err = nsq.NewProducer(str, nsq.NewConfig())
	if err != nil {
		panic(err)
	}
}

// 发布消息
func Publish(topic string, message string) error {
	var err error
	if producer != nil {
		if message == "" { //不能发布空串,否则会导致error
			return nil
		}
		err = producer.Publish(topic, []byte(message)) // 发布消息
		return err
	}
	return fmt.Errorf("producer is nil", err)
}

logs

2024/06/19 08:56:46 INF    1 (192.168.1.138:4160) connecting to nsqd
2024/06/19 08:56:46 ERR    1 (192.168.1.138:4160) error connecting to nsqd - failed to IDENTIFY - read tcp 192.168.1.128:61544->192.168.1.138:4160: wsarecv: An existing connection was forcibly closed by the remote host.
err:  failed to IDENTIFY - read tcp 192.168.1.128:61544->192.168.1.138:4160: wsarecv: An existing connection was forcibly closed by the remote host.
2024/06/19 08:56:55 INF    1 (192.168.1.138:4160) stopping

go.mod file

go 1.19
require github.com/nsqio/go-nsq v1.1.0
github.com/nsqio/go-nsq v1.1.0 h1:PQg+xxiUjA7V+TLdXw7nVrJ5Jbl3sN86EhGCQj4+FYE=
github.com/nsqio/go-nsq v1.1.0/go.mod h1:vKq36oyeVXgsS5Q8YEO7WghqidAVXQlcFxzQbQTuDEY=

@jehiah
Copy link
Member

jehiah commented Jun 21, 2024

Your producer code appears to be doing a Publish to 192.168.1.138:4160 which I think is your nsqlookupd instance. Producers need to publish to nsqd.

A Reader can use nsqlookupd to discover what nsqd instances have messages - but the producer doesn't involve nsqlookupd.

Please see the 2nd FAQ entry at https://nsq.io/overview/faq.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants