【发布时间】: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 :)