以下是我的rabbit服务器配置与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示例创建流,但不能创建生产者?
1条答案
按热度按时间d4so4syb1#
请阅读概述about stream
客户端必须能够查找它所连接的节点。您可以创建流的原因是因为它使用不同的连接。称为定位器。
当您请求生产者时,客户端查询流以了解领导者在哪里,然后尝试连接到节点领导者。
可能的解决方案:
1.使用localhost而不是
0.0.0.0
1.使用advertised_host和端口
要使用Docker,请参阅文档
字符串
然后:
型