Skip to content

Commit bf7e7cf

Browse files
authored
Merge pull request #123 from ibm-messaging/context
Enable PMO to pass Context
2 parents 19b946c + 6fd5d92 commit bf7e7cf

File tree

6 files changed

+71
-81
lines changed

6 files changed

+71
-81
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Changelog
22
Newest updates are at the top of this file.
33

4+
## October 7 2019 - v4.1.1
5+
* ibmmq - Enable use of Context in MQPMO structure (#122)
6+
* ibmmq - Remove unusable fields referring to Distribution List structures
7+
48
## Augest 20 2019 - v4.1.0
59
* Update Docker build scripts for newer Go compiler level
6-
* mqmetric - Issue warning if trying to monitor queues with names containing '/'
10+
* mqmetric - Issue warning if trying to monitor queues with names containing '/'
711

812
## August 2 2019 - unpublished
913
* ibmmq - Add new verb GetSlice to mirror Get() but which returns ready-sized buffer (#110)

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ let me know, via an issue, if you have another project that might be suitable fo
158158
### Package 'ibmmq'
159159
All regular MQI verbs are now available through the `ibmmq` package.
160160

161+
The only unimplemented area of MQI function is the use of Distribution Lists: they were
162+
rarely used, and the Publish/Subscribe operations provide similar capability.
163+
161164
### Package 'mqmetric'
162165
* There is currently a queue manager limitation which does not permit resource publications to
163166
be made about queues whose name includes '/'. Attempting to monitor such a queue will result in a warning

ibmmq/mqiMQOD.go

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ type MQOD struct {
4444
DynamicQName string
4545
AlternateUserId string
4646

47-
RecsPresent int32
48-
KnownDestCount int32
49-
UnknownDestCount int32
50-
InvalidDestCount int32
51-
ObjectRecOffset int32
52-
ResponseRecOffset int32
53-
54-
ObjectRecPtr C.MQPTR
55-
ResponseRecPtr C.MQPTR
47+
// TODO: These fields are not currently mapped. The Dist List feature is not
48+
// really supported here as Pub/Sub is the recommended approach.
49+
//RecsPresent int32
50+
//KnownDestCount int32
51+
//UnknownDestCount int32
52+
//InvalidDestCount int32
53+
//ObjectRec []MQOR
54+
//ResponseRec []MQOR
5655

5756
AlternateSecurityId []byte
5857
ResolvedQName string
@@ -77,16 +76,6 @@ func NewMQOD() *MQOD {
7776
od.DynamicQName = "AMQ.*"
7877
od.AlternateUserId = ""
7978

80-
od.RecsPresent = 0
81-
od.KnownDestCount = 0
82-
od.UnknownDestCount = 0
83-
od.InvalidDestCount = 0
84-
od.ObjectRecOffset = 0
85-
od.ResponseRecOffset = 0
86-
87-
od.ObjectRecPtr = nil
88-
od.ResponseRecPtr = nil
89-
9079
od.AlternateSecurityId = bytes.Repeat([]byte{0}, C.MQ_SECURITY_ID_LENGTH)
9180
od.ResolvedQName = ""
9281
od.ResolvedQMgrName = ""
@@ -137,15 +126,15 @@ func copyODtoC(mqod *C.MQOD, good *MQOD) {
137126
setMQIString((*C.char)(&mqod.DynamicQName[0]), good.DynamicQName, C.MQ_OBJECT_NAME_LENGTH)
138127
setMQIString((*C.char)(&mqod.AlternateUserId[0]), good.AlternateUserId, C.MQ_USER_ID_LENGTH)
139128

140-
mqod.RecsPresent = C.MQLONG(good.RecsPresent)
141-
mqod.KnownDestCount = C.MQLONG(good.KnownDestCount)
142-
mqod.UnknownDestCount = C.MQLONG(good.UnknownDestCount)
143-
mqod.InvalidDestCount = C.MQLONG(good.InvalidDestCount)
144-
mqod.ObjectRecOffset = C.MQLONG(good.ObjectRecOffset)
145-
mqod.ResponseRecOffset = C.MQLONG(good.ResponseRecOffset)
129+
mqod.RecsPresent = 0
130+
mqod.KnownDestCount = 0
131+
mqod.UnknownDestCount = 0
132+
mqod.InvalidDestCount = 0
133+
mqod.ObjectRecOffset = 0
134+
mqod.ResponseRecOffset = 0
146135

147-
mqod.ObjectRecPtr = good.ObjectRecPtr
148-
mqod.ResponseRecPtr = good.ResponseRecPtr
136+
mqod.ObjectRecPtr = nil
137+
mqod.ResponseRecPtr = nil
149138

150139
for i = 0; i < C.MQ_SECURITY_ID_LENGTH; i++ {
151140
mqod.AlternateSecurityId[i] = C.MQBYTE(good.AlternateSecurityId[i])
@@ -202,15 +191,12 @@ func copyODfromC(mqod *C.MQOD, good *MQOD) {
202191
good.DynamicQName = trimStringN((*C.char)(&mqod.DynamicQName[0]), C.MQ_OBJECT_NAME_LENGTH)
203192
good.AlternateUserId = trimStringN((*C.char)(&mqod.AlternateUserId[0]), C.MQ_USER_ID_LENGTH)
204193

205-
good.RecsPresent = int32(mqod.RecsPresent)
206-
good.KnownDestCount = int32(mqod.KnownDestCount)
207-
good.UnknownDestCount = int32(mqod.UnknownDestCount)
208-
good.InvalidDestCount = int32(mqod.InvalidDestCount)
209-
good.ObjectRecOffset = int32(mqod.ObjectRecOffset)
210-
good.ResponseRecOffset = int32(mqod.ResponseRecOffset)
211-
212-
good.ObjectRecPtr = mqod.ObjectRecPtr
213-
good.ResponseRecPtr = mqod.ResponseRecPtr
194+
//good.RecsPresent = int32(mqod.RecsPresent)
195+
//good.KnownDestCount = int32(mqod.KnownDestCount)
196+
//good.UnknownDestCount = int32(mqod.UnknownDestCount)
197+
//good.InvalidDestCount = int32(mqod.InvalidDestCount)
198+
//good.ObjectRecPtr = mqod.ObjectRecPtr
199+
//good.ResponseRecPtr = mqod.ResponseRecPtr
214200

215201
for i = 0; i < C.MQ_SECURITY_ID_LENGTH; i++ {
216202
good.AlternateSecurityId[i] = (byte)(mqod.AlternateSecurityId[i])

ibmmq/mqiMQPMO.go

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ import "C"
3232
MQPMO is a structure containing the MQ Put MessageOptions (MQPMO)
3333
*/
3434
type MQPMO struct {
35-
Version int32
36-
Options int32
37-
Timeout int32
38-
Context C.MQHOBJ
39-
KnownDestCount int32
40-
UnknownDestCount int32
41-
InvalidDestCount int32
42-
ResolvedQName string
43-
ResolvedQMgrName string
44-
RecsPresent int32
45-
PutMsgRecFields int32
46-
PutMsgRecOffset int32
47-
ResponseRecOffset int32
48-
PutMsgRecPtr C.MQPTR
49-
ResponseRecPtr C.MQPTR
35+
Version int32
36+
Options int32
37+
Timeout int32
38+
Context *MQObject
39+
KnownDestCount int32
40+
UnknownDestCount int32
41+
InvalidDestCount int32
42+
ResolvedQName string
43+
ResolvedQMgrName string
44+
45+
// TODO: These fields are not currently mapped. The Dist List feature is not
46+
// fully supported as Pub/Sub is the recommended approach.
47+
//RecsPresent int32
48+
//PutMsgRec []MQPMR
49+
//ResponseRec []MQRR
5050

5151
OriginalMsgHandle MQMessageHandle
5252
NewMsgHandle MQMessageHandle
@@ -64,18 +64,12 @@ func NewMQPMO() *MQPMO {
6464
pmo.Version = int32(C.MQPMO_VERSION_1)
6565
pmo.Options = int32(C.MQPMO_NONE)
6666
pmo.Timeout = -1
67-
pmo.Context = 0
67+
pmo.Context = nil
6868
pmo.KnownDestCount = 0
6969
pmo.UnknownDestCount = 0
7070
pmo.InvalidDestCount = 0
7171
pmo.ResolvedQName = ""
7272
pmo.ResolvedQMgrName = ""
73-
pmo.RecsPresent = 0
74-
pmo.PutMsgRecFields = 0
75-
pmo.PutMsgRecOffset = 0
76-
pmo.ResponseRecOffset = 0
77-
pmo.PutMsgRecPtr = nil
78-
pmo.ResponseRecPtr = nil
7973

8074
pmo.OriginalMsgHandle.hMsg = C.MQHM_NONE
8175
pmo.NewMsgHandle.hMsg = C.MQHM_NONE
@@ -92,20 +86,22 @@ func copyPMOtoC(mqpmo *C.MQPMO, gopmo *MQPMO) {
9286

9387
mqpmo.Options = C.MQLONG(gopmo.Options) | C.MQPMO_FAIL_IF_QUIESCING
9488
mqpmo.Timeout = C.MQLONG(gopmo.Timeout)
95-
mqpmo.Context = gopmo.Context
89+
if gopmo.Context != nil {
90+
mqpmo.Context = gopmo.Context.hObj
91+
}
9692
mqpmo.KnownDestCount = C.MQLONG(gopmo.KnownDestCount)
9793
mqpmo.UnknownDestCount = C.MQLONG(gopmo.UnknownDestCount)
9894
mqpmo.InvalidDestCount = C.MQLONG(gopmo.InvalidDestCount)
9995

10096
setMQIString((*C.char)(&mqpmo.ResolvedQName[0]), gopmo.ResolvedQName, C.MQ_OBJECT_NAME_LENGTH)
10197
setMQIString((*C.char)(&mqpmo.ResolvedQMgrName[0]), gopmo.ResolvedQMgrName, C.MQ_OBJECT_NAME_LENGTH)
10298

103-
mqpmo.RecsPresent = C.MQLONG(gopmo.RecsPresent)
104-
mqpmo.PutMsgRecFields = C.MQLONG(gopmo.PutMsgRecFields)
105-
mqpmo.PutMsgRecOffset = C.MQLONG(gopmo.PutMsgRecOffset)
106-
mqpmo.ResponseRecOffset = C.MQLONG(gopmo.ResponseRecOffset)
107-
mqpmo.PutMsgRecPtr = gopmo.PutMsgRecPtr
108-
mqpmo.ResponseRecPtr = gopmo.ResponseRecPtr
99+
mqpmo.RecsPresent = 0
100+
mqpmo.PutMsgRecFields = 0
101+
mqpmo.PutMsgRecOffset = 0
102+
mqpmo.ResponseRecOffset = 0
103+
mqpmo.PutMsgRecPtr = nil
104+
mqpmo.ResponseRecPtr = nil
109105

110106
if gopmo.OriginalMsgHandle.hMsg != C.MQHM_NONE {
111107
mqpmo.OriginalMsgHandle = gopmo.OriginalMsgHandle.hMsg
@@ -131,20 +127,20 @@ func copyPMOfromC(mqpmo *C.MQPMO, gopmo *MQPMO) {
131127

132128
gopmo.Options = int32(mqpmo.Options)
133129
gopmo.Timeout = int32(mqpmo.Timeout)
134-
gopmo.Context = mqpmo.Context
130+
//gopmo.Context = mqpmo.Context // This is input only so don't copy back
135131
gopmo.KnownDestCount = int32(mqpmo.KnownDestCount)
136132
gopmo.UnknownDestCount = int32(mqpmo.UnknownDestCount)
137133
gopmo.InvalidDestCount = int32(mqpmo.InvalidDestCount)
138134

139135
gopmo.ResolvedQName = trimStringN((*C.char)(&mqpmo.ResolvedQName[0]), C.MQ_OBJECT_NAME_LENGTH)
140136
gopmo.ResolvedQMgrName = trimStringN((*C.char)(&mqpmo.ResolvedQMgrName[0]), C.MQ_OBJECT_NAME_LENGTH)
141137

142-
gopmo.RecsPresent = int32(mqpmo.RecsPresent)
143-
gopmo.PutMsgRecFields = int32(mqpmo.PutMsgRecFields)
144-
gopmo.PutMsgRecOffset = int32(mqpmo.PutMsgRecOffset)
145-
gopmo.ResponseRecOffset = int32(mqpmo.ResponseRecOffset)
146-
gopmo.PutMsgRecPtr = mqpmo.PutMsgRecPtr
147-
gopmo.ResponseRecPtr = mqpmo.ResponseRecPtr
138+
//gopmo.RecsPresent = int32(mqpmo.RecsPresent)
139+
//gopmo.PutMsgRecFields = int32(mqpmo.PutMsgRecFields)
140+
//gopmo.PutMsgRecOffset = int32(mqpmo.PutMsgRecOffset)
141+
//gopmo.ResponseRecOffset = int32(mqpmo.ResponseRecOffset)
142+
//gopmo.PutMsgRecPtr = mqpmo.PutMsgRecPtr
143+
//gopmo.ResponseRecPtr = mqpmo.ResponseRecPtr
148144

149145
gopmo.OriginalMsgHandle.hMsg = mqpmo.OriginalMsgHandle
150146
gopmo.NewMsgHandle.hMsg = mqpmo.NewMsgHandle

mqmetric/discover.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ const defaultMaxQDepth = 5000
9898
var Metrics AllMetrics
9999

100100
// Only issue the warning about a '/' in queue name once.
101-
var globalSlashWarning = false;
102-
var localSlashWarning = false;
101+
var globalSlashWarning = false
102+
var localSlashWarning = false
103103

104104
var qInfoMap map[string]*QInfo
105105
var locale string
@@ -554,25 +554,25 @@ func discoverQueues(monitoredQueuePatterns string) error {
554554
qList, err = inquireObjects(monitoredQueuePatterns, ibmmq.MQOT_Q)
555555
}
556556

557-
localSlashWarning = false
557+
localSlashWarning = false
558558
if len(qList) > 0 {
559559
//fmt.Printf("Monitoring Queues: %v\n", qList)
560560
for i := 0; i < len(qList); i++ {
561561
var qInfoElem *QInfo
562562
var ok bool
563563
qName := strings.TrimSpace(qList[i])
564564

565-
// If the qName contains a '/' - eg "DEV/QUEUE/1" then the queue manager will
565+
// If the qName contains a '/' - eg "DEV/QUEUE/1" then the queue manager will
566566
// not (right now) process resource publications correctly. Hopefully that will get
567567
// fixed at some point, but we will issue a warning here. The same problem happens with
568568
// amqsrua; there's no workround possible outside of the qmgr code.
569569
//
570570
// Because of the possible complexities of pattern matching, we don't
571571
// actually fail the discovery process, but instead issue a warning and continue with
572572
// other queues.
573-
if strings.Contains(qName,"/") && globalSlashWarning == false {
573+
if strings.Contains(qName, "/") && globalSlashWarning == false {
574574
localSlashWarning = true // First time through, issue the warning for all queues
575-
logError("Warning: Cannot subscribe to queue containing '/': %s",qName)
575+
logError("Warning: Cannot subscribe to queue containing '/': %s", qName)
576576
continue
577577
}
578578

@@ -749,7 +749,7 @@ func inquireObjects(objectPatternsList string, objectType int32) ([]string, erro
749749
for i := 0; i < len(elem.String); i++ {
750750
s := strings.TrimSpace(elem.String[i])
751751

752-
objectList = append(objectList, s)
752+
objectList = append(objectList, s)
753753

754754
}
755755
}

mqmetric/log.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ func logInfo(format string, v ...interface{}) {
4545
logger.Info(format, v...)
4646
}
4747
}
48+
4849
// Errors should be reported always
4950
func logError(format string, v ...interface{}) {
5051
if logger != nil && logger.Error != nil {
5152
logger.Error(format, v...)
5253
} else {
53-
fmt.Printf(format,v...)
54+
fmt.Printf(format, v...)
5455
}
5556
}

0 commit comments

Comments
 (0)