duandi5328 2016-03-09 16:18
浏览 142
已采纳

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

How do we connect to ActiveMQ using failover stomp connection URI in Go? Using Go-Stomp client, I tried below code and it fails to connect.

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))
    }
  • 写回答

2条回答 默认 最新

  • dongshubang7816 2016-03-10 21:16
    关注

    Due to lack of support for failover, had to write some code to achieve the desired result.

    //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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 软件供应链安全是跟可靠性有关还是跟安全性有关?
  • ¥15 电脑蓝屏logfilessrtsrttrail问题
  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)
  • ¥15 【求职】怎么找到一个周围人素质都很高不会欺负他人,并且未来月薪能够达到一万以上(技术岗)的工作?希望可以收到写有具体,可靠,已经实践过了的路径的回答?
  • ¥15 Java+vue部署版本反编译
  • ¥100 对反编译和ai熟悉的开发者。
  • ¥15 带序列特征的多输出预测模型
  • ¥15 Python 如何安装 distutils模块
  • ¥15 关于#网络#的问题:网络是从楼上引一根网线下来,接了2台傻瓜交换机,也更换了ip还是不行
  • ¥15 资源泄露软件闪退怎么解决?