Skip to content

Commit 72cbde8

Browse files
committed
Better config checks
1 parent f9bbbef commit 72cbde8

File tree

5 files changed

+79
-9
lines changed

5 files changed

+79
-9
lines changed

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ export CGO_LDFLAGS_ALLOW="-Wl,-rpath.*"
7777
### Windows
7878

7979
* Install the Go runtime and compiler. On Windows, the common directory is `c:\Go`
80-
* Ensure you have a gcc-based compiler, for example from the Cygwin distribution. I use the mingw variation, to ensure compiled code can be used on systems without Cygwin installed
80+
* Ensure you have a gcc-based compiler, for example from the Cygwin distribution.
81+
I recommend you use the mingw variation, to ensure compiled code can be used on systems without Cygwin installed.
82+
The default `gcc` compiler from Cygwin does not work because it tries to build a
83+
Cygwin-enabled executable but the MQ libraries do not work in that model;
84+
the `mingw` versions build Windows-native programs.
8185
* Create a working directory. For example, `mkdir c:\Gowork`
8286
* Set environment variables. Based on the previous lines,
8387

@@ -99,11 +103,21 @@ set CC=x86_64-w64-mingw32-gcc.exe
99103
`git clone https://github.com/ibm-messaging/mq-golang.git src/github.com/ibm-messaging/mq-golang`
100104

101105
* If you have not installed MQ libraries into the default location, then set environment variables
102-
for the C compiler to recognise those directories. For example,
106+
for the C compiler to recognise those directories. You may get messages from the compiler
107+
saying that the default MQ directories cannot be found, but those warnings can be ignored.
108+
The exact values for these environment variables will vary by platform, but follow the
109+
corresponding CFLAGS/LDFLAGS values in `mqi.go`
110+
111+
For example,
103112

104113
```
105-
export CGO_CFLAGS="-I/my/mq/dir/inc"
106-
export CGO_LDFLAGS="-I/my/mq/dir/lib64"
114+
export MQ_INSTALLATION_PATH=/my/mq/dir # This will also be set from the setmqenv command
115+
116+
export CGO_CFLAGS="-I$MQ_INSTALLATION_PATH/inc"
117+
118+
export CGO_LDFLAGS="-L$MQ_INSTALLATION_PATH/lib64 -Wl,rpath=$MQ_INSTALLATION_PATH/lib64"
119+
or on Darwin
120+
export CGO_LDFLAGS="-L$MQ_INSTALLATION_PATH/lib64 -Wl,rpath,$MQ_INSTALLATION_PATH/lib64"
107121
```
108122

109123
* Compile the `ibmmq` component:
@@ -144,4 +158,4 @@ in the CLA.
144158

145159
## Copyright
146160

147-
© Copyright IBM Corporation 2016, 2018
161+
© Copyright IBM Corporation 2016, 2019

ibmmq/mqi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ package ibmmq
4343
/*
4444
#cgo !windows CFLAGS: -I/opt/mqm/inc -D_REENTRANT
4545
#cgo windows CFLAGS: -I"C:/Program Files/IBM/MQ/Tools/c/include"
46-
#cgo !windows,!darwin LDFLAGS: -L/opt/mqm/lib64 -lmqm_r -Wl,-rpath=/opt/mqm/lib64 -Wl,-rpath=/usr/lib64
47-
#cgo darwin LDFLAGS: -L/opt/mqm/lib64 -lmqm_r -Wl,-rpath,/opt/mqm/lib64 -Wl,-rpath=/usr/lib64
46+
#cgo !windows,!darwin LDFLAGS: -L/opt/mqm/lib64 -lmqm_r -Wl,-rpath,/opt/mqm/lib64 -Wl,-rpath,/usr/lib64
47+
#cgo darwin LDFLAGS: -L/opt/mqm/lib64 -lmqm_r -Wl,-rpath,/opt/mqm/lib64 -Wl,-rpath,/usr/lib64
4848
#cgo windows LDFLAGS: -L "C:/Program Files/IBM/MQ/bin64" -lmqm
4949
5050
#include <stdlib.h>

mqmetric/discover.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ var Metrics AllMetrics
9191

9292
var qList []string
9393
var locale string
94+
var discoveryDone = false
9495

9596
func GetDiscoveredQueues() []string {
9697
return qList
@@ -105,12 +106,60 @@ func SetLocale(l string) {
105106
}
106107

107108
/*
108-
DiscoverAndSubscribe does all the work of finding the
109+
* Check any important parameters - this must be called after DiscoverAndSubscribe
110+
* to maintain compatibility of the package's APIs. It also needs the qList to have been
111+
* populated first which is also done in DiscoverAndSubscribe.
112+
* Returns: an MQ CompCode, error string. CompCode can be MQCC_OK, WARNING or ERROR.
113+
*/
114+
func VerifyConfig() (int32, error) {
115+
var err error
116+
var v map[int32]interface{}
117+
var compCode = ibmmq.MQCC_OK
118+
if !discoveryDone {
119+
err = fmt.Errorf("Error: Need to call DiscoverAndSubscribe first")
120+
compCode = ibmmq.MQCC_FAILED
121+
}
122+
123+
if err == nil {
124+
selectors := []int32{ibmmq.MQIA_MAX_Q_DEPTH, ibmmq.MQIA_DEFINITION_TYPE}
125+
v, err = replyQObj.InqMap(selectors)
126+
if err == nil {
127+
maxQDepth := v[ibmmq.MQIA_MAX_Q_DEPTH].(int32)
128+
// Function has tuning based on number of queues to be monitored
129+
// Current published resource topics are approx 95 for qmgr
130+
// ... and 35 per queue
131+
// Make recommended minimum qdepth 60 / 10 * total per interval to allow one minute of data
132+
// as MQ publications are at 10 second interval by default (and no public tuning)
133+
// and monitor collection interval is one minute
134+
recommendedDepth := (100 + len(qList)*50) * 6
135+
if maxQDepth < int32(recommendedDepth) {
136+
err = fmt.Errorf("Warning: Maximum queue depth on %s may be too low. Current value = %d", replyQBaseName, maxQDepth)
137+
compCode = ibmmq.MQCC_WARNING
138+
}
139+
140+
// Make sure this reply queue that has been opened is not a predefined queue, so it
141+
// has come from a model definition. The base replyQ is opened twice for different reasons.
142+
// A LOCAL queue would end up with mixed sets of replies/publications
143+
defType := v[ibmmq.MQIA_DEFINITION_TYPE].(int32)
144+
if defType == ibmmq.MQQDT_PREDEFINED {
145+
err = fmt.Errorf("Error: ReplyQ parameter %s must refer to a MODEL queue,", replyQBaseName)
146+
compCode = ibmmq.MQCC_FAILED
147+
}
148+
}
149+
}
150+
return compCode, err
151+
}
152+
153+
/*
154+
DiscoverAndSubscribe does the work of finding the
109155
different resources available from a queue manager and
110156
issuing the MQSUB calls to collect the data
111157
*/
112158
func DiscoverAndSubscribe(queueList string, checkQueueList bool, metaPrefix string) error {
113159
var err error
160+
161+
discoveryDone = true
162+
114163
// What metrics can the queue manager provide?
115164
if err == nil {
116165
err = discoverStats(metaPrefix)

mqmetric/mqif.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var (
3434
qMgr ibmmq.MQQueueManager
3535
cmdQObj ibmmq.MQObject
3636
replyQObj ibmmq.MQObject
37+
replyQBaseName string
3738
statusReplyQObj ibmmq.MQObject
3839
getBuffer = make([]byte, 32768)
3940
platform int32
@@ -133,9 +134,11 @@ func InitConnection(qMgrName string, replyQ string, cc *ConnectionConfig) error
133134
if err == nil {
134135
mqod := ibmmq.NewMQOD()
135136
openOptions := ibmmq.MQOO_INPUT_AS_Q_DEF | ibmmq.MQOO_FAIL_IF_QUIESCING
137+
openOptions |= ibmmq.MQOO_INQUIRE
136138
mqod.ObjectType = ibmmq.MQOT_Q
137139
mqod.ObjectName = replyQ
138140
replyQObj, err = qMgr.Open(mqod, openOptions)
141+
replyQBaseName = replyQ
139142
if err == nil {
140143
queuesOpened = true
141144
}

samples/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,16 @@ aspect.
4141
Apart from the `amqsconn.go` program, the other samples are designed to either connect
4242
to a local queue manager (on the same machine) or for the client configuration to be
4343
provided externally such as by the MQSERVER environment variable or the
44-
MQ Client Channel Definition Table (CCDT) file.
44+
MQ Client Channel Definition Table (CCDT) file. The MQ_CONNECT_TYPE environment
45+
variable can be used to force client connections to be made, even if you have
46+
installed the full server product; that variable is not needed if you have
47+
only installed the MQ client libraries.
4548

4649
For example
4750

4851
```
4952
export MQSERVER="SYSTEM.DEF.SVRCONN/TCP/localhost(1414)"
53+
export MQ_CONNECT_TYPE=CLIENT
5054
go run amqsput.go DEV.QUEUE.1 QM1
5155
```
5256

0 commit comments

Comments
 (0)