apache / rocketmq-client-go

Apache RocketMQ go client
https://rocketmq.apache.org/
Apache License 2.0
1.31k stars 423 forks source link

使用阿里云RocketMQ时无法使用域名,报错: new Namesrv failed.: IP addr error #920

Closed KilluaaaCHEN closed 2 years ago

KilluaaaCHEN commented 2 years ago

代码片段

c, err := rocketmq.NewPushConsumer(
  consumer.WithGroupName("test-group"),
  consumer.WithNsResolver(primitive.NewPassthroughResolver([]string{"rmq-cn-123456.cn-shanghai.rmq.aliyuncs.com:8080"})),
  consumer.WithCredentials(primitive.Credentials{
      AccessKey: "111",
      SecretKey: "222",
  }),
)

运行报错:

init consumer error: new Namesrv failed.: IP addr error

版本信息

现状

目前是使用ping 解析出ip后,再进行配置,例如ping rmq-cn-123456.cn-shanghai.rmq.aliyuncs.com得到10.1.2.3.4

Ikepi commented 2 years ago

hi, chen, i think u can try this: c, err := rocketmq.NewPushConsumer( consumer.WithGroupName("test-group"), consumer.WithNsResolver(primitive.NewPassthroughResolver([]string{"http://rmq-cn-123456.cn-shanghai.rmq.aliyuncs.com:8080"})), consumer.WithCredentials(primitive.Credentials{ AccessKey: "111", SecretKey: "222", }), )

KilluaaaCHEN commented 2 years ago

hi, chen, i think u can try this: c, err := rocketmq.NewPushConsumer( consumer.WithGroupName("test-group"), consumer.WithNsResolver(primitive.NewPassthroughResolver([]string{"http://rmq-cn-123456.cn-shanghai.rmq.aliyuncs.com:8080"})), consumer.WithCredentials(primitive.Credentials{ AccessKey: "111", SecretKey: "222", }), )

Thanks, now it's working