ibm-messaging / mq-golang

Calling IBM MQ from Go applications
Apache License 2.0
168 stars 60 forks source link

How to connect using a ccdt #97

Closed wcn00 closed 5 years ago

wcn00 commented 5 years ago

Using the mq 9.1 client and current mq-golang repo.
I have my app working with regular client connections, and TLS client connections but would like to have the option of using a CCDT. Can't get it to connect thought. I'm using this table for a java connection which works.
I've been playing around with the sample but can't get it to connect. Just using plain sockets for now.
Here's one version of the main which is getting host not available (but it should look the host up from the ccdt...)

func main() { var qMgrName string var err error var qMgr ibmmq.MQQueueManager var rc int

// Which queue manager do we want to connect to
qMgrName = "centosmq9"

// Allocate the MQCNO and MQCD structures needed for the CONNX call.
cno := ibmmq.NewMQCNO()
sco := ibmmq.NewMQSCO()
cd := ibmmq.NewMQCD()

// Fill in required fields in the MQCD channel definition structure
cd.ChannelName = "SVRCONN"
//cd.ConnectionName = "centosmq9(1414)" /// host port or whatever.  Lets see if we can replace it with ccdt

// The CipherSpec must match what is configured on the corresponding SVRCONN
//cd.SSLCipherSpec = "TLS_RSA_WITH_AES_256_CBC_SHA"

// The ClientAuth field says whether or not the client needs to present its own certificate
// This too must match the SVRCONN definition.
cd.SSLClientAuth = ibmmq.MQSCA_OPTIONAL

//sco.KeyRepository = "/gil/local/pub/certs/centosmq9/client"

// use the client connection method.
cno.ClientConn = cd
cno.Options = ibmmq.MQCNO_CLIENT_BINDING
cno.SSLConfig = sco
cno.CCDTUrl = "file:///gil/local/pub/@ipcc/centosmq9/AMQCLCHL.TAB"

// Also fill in the userid and password if the MQSAMP_USER_ID
// environment variable is set. This is the same variable used by the C
// sample programs such as amqsput shipped with the MQ product.
userId := "wcn00"
if userId != "" {
    csp := ibmmq.NewMQCSP()
    csp.AuthenticationType = ibmmq.MQCSP_AUTH_USER_ID_AND_PWD
    csp.UserId = userId
    csp.Password = "somepw"

    // Make the CNO refer to the CSP structure so it gets used during the connection
    cno.SecurityParms = csp
}

// And now we can try to connect. Wait a short time before disconnecting.
qMgr, err = ibmmq.Connx(qMgrName, cno)
if err == nil {
    fmt.Printf("Connection to %s succeeded.\n", qMgrName)
    d, _ := time.ParseDuration("3s")
    time.Sleep(d)
    qMgr.Disc() // Ignore errors from disconnect as we can't do much about it anyway
    rc = 0
} else {
    fmt.Printf("Connection to %s failed.\n", qMgrName)
    fmt.Println(err)
    rc = int(err.(*ibmmq.MQReturn).MQCC)
}

fmt.Println("Done.")
os.Exit(rc)

}

Thoughts? wnc

ibmmqmet commented 5 years ago

Don't use the MQCD if you want to use the CCDT. Comment out "cno.ClientConn=cd".

ibmmqmet commented 5 years ago

closing as answered