【问题标题】:Golang send messages to IBM MQ Error MQRC_CONNECTION_BROKENGolang 向 IBM MQ 发送消息错误 MQRC_CONNECTION_BROKEN
【发布时间】:2021-06-15 12:13:23
【问题描述】:

我现在正在使用 Golang 连接 IBM Websphere MQ-ESB 和用于与 MQ-ESB 通信的库

https://github.com/ibm-messaging/mq-golang
https://github.com/ibm-messaging/mq-golang-jms20

一般情况下,它可以将消息发送到 MQ-ESB ,但是当发生错误时,会出现错误 MQ Connection Broken。这导致我的应用程序无法再将消息发送到 MQ-ESB。重新启动服务是解决此问题的方法(但不是解决方法)。有人有想法吗? 谢谢

这是创建 mq 连接的代码

func NewIBMMQConnection(mqConnConfig *mqjms.ConnectionFactoryImpl) jms20subset.JMSContext {
if !viper.GetBool("mq.openconnection") {
    return &mqjms.ContextImpl{}
}

logx.WithFields(logrus.Fields{
    "queue manager": viper.GetString("mq.qManager"),
    "host":          viper.GetString("mq.host"),
    "port":          viper.GetInt("mq.port"),
    "channel":       viper.GetString("mq.qChannel"),
}).Infof("[CONFIG] [MDM IBMMQ]")

conn, exception := mqConnConfig.CreateContext()
if exception != nil {
    if exception.GetLinkedError() != nil {
        logx.Fatalf("new mdm mq error: %s", exception.GetLinkedError())
    }
}
return conn
}

func NewIBMMQConfig() *mqjms.ConnectionFactoryImpl {
    return &mqjms.ConnectionFactoryImpl{
        QMName:      viper.GetString("mq.qManager"),
        Hostname:    viper.GetString("mq.host"),
        PortNumber:  viper.GetInt("mq.port"),
        ChannelName: viper.GetString("mq.qChannel"),
        UserName:    viper.GetString("mq.login"),
        Password:    viper.GetString("mq.pass"),
    }
}

这是main.go 中用于实例化连接的代码

func main() {
    db := newGormDB()
    defer closeDB(db)

    mq := ibmmq.NewIBMMQConnection(ibmmq.NewIBMMQConfig())
    defer mq.Close()
    ibmmq := ibmmq.New(mq)

    ...

    ... 

    go startServer()

    shutdown()
}

这是代码生成消息

func (i *IBMMQ) ProduceMSGToMQ(ctx context.Context, msg string) error {
logx.WithContext(ctx).Infof("Producing Message queueName: message: %s", msg)
err := i.producer.SendString(i.queueCDDEMoeny, msg)

if err != nil {
    logx.WithSeverityError(ctx).Errorf("Send msg to mq error: %s", err.GetErrorCode()+"-"+err.GetReason()+"-"+err.GetLinkedError().Error())
    return errors.New("Send msg to mq error: " + err.GetErrorCode() + "-" + err.GetReason() + "-" + err.GetLinkedError().Error())
}
return nil
}

【问题讨论】:

  • 您能否展示您的代码,特别是您的代码在收到 MQRC_CONNECTION_BROKEN 错误时会做什么。
  • 当然@MoragHughson。 func (i *IBMMQ) ProduceMSGToMQ(ctx context.Context, msg string) error { logx.WithContext(ctx).Infof("Producing Message queueName: message: %s", msg) err := i.producer.SendString(i.queueCDDEMoeny, msg) if err != nil { logx.WithSeverityError(ctx).Errorf("Send msg to mq error: %s", err.GetErrorCode()+"-"+err.GetReason()) return errors.New("Send msg to mq error: " + err.GetErrorCode() + "-" + err.GetReason()) } return nil }
  • 这很难读。你能编辑你的问题,然后把它放在那里吗?
  • 另外,我没有看到任何连接到队列管理器的代码?
  • @MoragHughson 好的,我已经更新了创建连接和配置的 sn-p :)

标签: go ibm-mq esb


【解决方案1】:

我不是 Go 语言专家,只是一名 IBM MQ 专家,但这里有(不是双关语!)。

我看不到您在哪里调用 ProduceMSGToMQ 函数,但我想像这样:-

error := ibmmq.ProduceMSGToMQ(...)
if error != nil && (error.GetReason() == "MQRC_CONNECTION_BROKEN") {
    mq := ibmmq.NewIBMMQConnection(ibmmq.NewIBMMQConfig())
}

希望能有所帮助。

【讨论】:

    【解决方案2】:

    我们还必须重新启动服务以恢复 MQ 客户端上的连接。 但是设置了重连选项后问题就解决了。

    mqcno := ibmmq.NewMQCNO()
    ...
    ...
    mqcno.Options = ibmmq.MQCNO_CLIENT_BINDING
    mqcno.Options |= ibmmq.MQCNO_RECONNECT_Q_MGR
    

    【讨论】:

      猜你喜欢
      • 2019-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-08
      • 1970-01-01
      • 2018-09-14
      • 1970-01-01
      • 2015-06-30
      相关资源
      最近更新 更多