go - go stomp 客户端中 ActiveMQ 的故障转移 URI

标签 go activemq stomp

我们如何在 Go 中使用故障转移 stomp 连接 URI 连接到 ActiveMQ? 使用Go-Stomp客户端,我尝试了以下代码,但无法连接。

if conn, err = stomp.Dial("tcp", "failover:(tcp://10.01.02.03:61613,tcp://10.04.05.06:61613)?startupMaxReconnectAttempts=2"); err != nil {
        panic(fmt.Sprintf("Could not connect to ActiveMQ using brokerUri %v. Can not continue.", Config.Broker.URI))
    }

最佳答案

由于缺乏对故障转移的支持,不得不编写一些代码来达到预期的结果。

//connect to ActiveMQ using failover approach
    var err error
    for _, uri := range ["10.01.02.03:61613","10.04.05.06:61613", {
        if err = connect(uri); err == nil {
            break
        }
    }
    if conn == nil {
        panic(fmt.Sprintf("Could not connect to ActiveMQ using brokerUri. Can not continue."))
    }

func connect(brokerIp string) (err error) {
    log.Printf("Attempting to connect to ActiveMQ node %v", brokerIp)
    if conn, err = stomp.Dial("tcp",
        brokerIp,
        stomp.ConnOpt.Login(Broker.User, Broker.Password)); err != nil {
        log.Printf("Faild to connect to ActiveMQ using %v", brokerIp)
    }
    if err == nil {
        log.Printf("Successfully connected to ActiveMQ node %v", brokerIp)
    }
    return
}

关于go - go stomp 客户端中 ActiveMQ 的故障转移 URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35896944/

相关文章:

php - 相当于 PHP 的 'implode'

multithreading - 从不同线程中的繁重操作同步写入文件

java - 带有外部 Activity MQ 的 JBoss FUSE 7.4 给出 AMQ219013 : Timed out waiting to receive cluster topology. Group:null

java - 将 Log4J JMSAppender 与 ActiveMQ 结合使用

spring - ActiveMQ 的消息被重新传送(PooledConnectionFactory 配置错误可疑)

javascript - 奇怪的 IE 7 javascript 问题

java - 将自定义字段添加到 STOMP 消息的 header 中

rest - 测试基于 gin 的 REST API 在使用 net/http/httptest 时没有获取参数

go - 如何在protoregistry中加载.proto文件

stomp - 如何在 apache artemis 中安排消息