这是我的兔子服务器配置与 docker-compose:
服务:
rabbitmq:
image: rabbitmq:3-management
container_name: "vibe-rabbitmq"
volumes:
- rabbitmq_data:/var/lib/rabbitmq
ports:
- "5672:5672"
- "15672:15672"
- "5552:5552"
environment:
- RABBITMQ_PLUGINS=rabbitmq_stream,rabbitmq_stream_management
- RABBITMQ_DEFAULT_USER=rabbitmq
- RABBITMQ_DEFAULT_PASS=rabbitmq
这是我的 golang 代码
package main
import (
"fmt"
"github.com/rabbitmq/rabbitmq-stream-go-client/pkg/amqp"
"github.com/rabbitmq/rabbitmq-stream-go-client/pkg/stream"
"log"
"time"
)
func main() {
streamName := "your_stream_name"
env, err := stream.NewEnvironment(
stream.NewEnvironmentOptions().
SetHost("0.0.0.0").
SetPort(5552). // 5552
SetUser("rabbitmq").
SetPassword("rabbitmq"),
)
if err != nil {
log.Fatalf("Failed to create environment: %s", err)
}
err = env.DeclareStream(streamName, &stream.StreamOptions{})
if err != nil {
log.Fatalf("Failed to declare stream: %v", err)
}
log.Printf("Stream '%s' created successfully", streamName)
producer, err := env.NewProducer(streamName, &stream.ProducerOptions{})
if err != nil {
log.Fatalf("Failed to create producer: %s", err)
}
}
我运行上面的命令,然后出现此错误:
2023/12/14 18:15:17 Stream 'your_stream_name' created successfully
2023/12/14 18:15:17 Failed to create producer: dial tcp: missing address
exit status 1
非常奇怪的是我可以使用 env 实例创建流,但无法创建生产者?
请阅读概述关于流
客户端必须能够查找其连接的节点。 您可以创建流的原因是因为它使用不同的连接。称为定位器。
当您请求生产者时,客户端会查询流以了解领导者在哪里,然后尝试连接到节点领导者。
可能的解决方案:
0.0.0.0