在 Docker 中部署的 Go 应用程序中消费 ActiveMQ 消息时出现连接拒绝错误

问题描述 投票:0回答:1

我在使用 Go 应用程序使用来自 ActiveMQ 服务的消息时遇到问题。 ActiveMQ 服务在我的本地 Tomcat 服务器上的 Java 应用程序中运行,该应用程序生成主题。在我的 Go 应用程序中,我使用 STOMP 库来使用这些主题。但是,当我尝试连接时,我收到以下错误:

拨打 tcp 127.0.0.1:61616: connect: 连接被拒绝。

我可以在 Java 中收到相同的消息,但不能从 Go 中收到。我已在 Docker 容器中部署了我的 Go 项目。

Java代码:

ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("", "", "tcp://localhost:61616");

            if (transportListener != null) {
                connectionFactory.setTransportListener(transportListener);
            }

            final Connection connection = Objects.requireNonNull(connectionFactory.createConnection());
            this.connection = connection;

            if (serviceExceptionListener != null) {
                connection.setExceptionListener(serviceExceptionListener);
            }
            else {
                connection.setExceptionListener(this);
            }
            connection.start();

高郎:

import (
    "github.com/go-stomp/stomp/v3"
)

func main() {

    conn, error := stomp.Dial("tcp", "localhost:61616")

    fmt.Println("Printing conn 2 ", error.Error())
}
go activemq stomp
1个回答
0
投票

A

connection refused
表示 Go 应用程序无法通过网络到达 STOMP 服务器。这几乎肯定是您的环境中的问题(例如 Docker 容器和代理之间的网络)。

© www.soinside.com 2019 - 2024. All rights reserved.