Skip to content

Commit 99a6892

Browse files
authored
Merge pull request #94 from ibm-messaging/cbmh2
Make callbacks explicitly pass the hConn (#93)
2 parents 5e39ebf + 9890926 commit 99a6892

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
Newest updates are at the top of this file.
33

4+
## March 26 2019
5+
* BREAKING API: Add hConn to callback function
6+
* Callbacks not setting hConn correctly (#93)
7+
48
## March 20 2019 - v4.0.0
59
* Update for MQ 9.1.2 - ApplName now settable during Connect
610
* BREAKING API: deprecated Inq()/MQINQ implementation replaced.

ibmmq/mqicb.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
)
3939

4040
// The user's callback function must match this signature
41-
type MQCB_FUNCTION func(*MQObject, *MQMD, *MQGMO, []byte, *MQCBC, *MQReturn)
41+
type MQCB_FUNCTION func(*MQQueueManager, *MQObject, *MQMD, *MQGMO, []byte, *MQCBC, *MQReturn)
4242

4343
// Need to keep references to the user's callback function and some other
4444
// structure elements which do not map to the C functions, or do not need to
@@ -119,14 +119,17 @@ func MQCALLBACK_Go(hConn C.MQHCONN, mqmd *C.MQMD, mqgmo *C.MQGMO, mqBuffer C.PMQ
119119
}
120120

121121
if ok {
122+
if gogmo.MsgHandle.hMsg != C.MQHM_NONE {
123+
gogmo.MsgHandle.qMgr = cbHObj.qMgr
124+
}
122125

123126
gocbc.CallbackArea = info.callbackArea
124127
gocbc.ConnectionArea = info.connectionArea
125128

126129
// Get the data
127130
b := C.GoBytes(unsafe.Pointer(mqBuffer), C.int(mqcbc.DataLength))
128131
// And finally call the user function
129-
info.callbackFunction(cbHObj, gomd, gogmo, b, gocbc, mqreturn)
132+
info.callbackFunction(cbHObj.qMgr, cbHObj, gomd, gogmo, b, gocbc, mqreturn)
130133
}
131134
}
132135

samples/amqscb.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141

4242
var qMgrObject ibmmq.MQObject
4343
var qObject ibmmq.MQObject
44+
var mh ibmmq.MQMessageHandle
4445

4546
var ok = true
4647

@@ -50,7 +51,7 @@ func main() {
5051
}
5152

5253
// This is the callback function invoked when a message arrives on the queue.
53-
func cb(hObj *ibmmq.MQObject, md *ibmmq.MQMD, gmo *ibmmq.MQGMO, buffer []byte, cbc *ibmmq.MQCBC, err *ibmmq.MQReturn) {
54+
func cb(hConn *ibmmq.MQQueueManager, hObj *ibmmq.MQObject, md *ibmmq.MQMD, gmo *ibmmq.MQGMO, buffer []byte, cbc *ibmmq.MQCBC, err *ibmmq.MQReturn) {
5455
buflen := len(buffer)
5556
if err.MQCC != ibmmq.MQCC_OK {
5657
fmt.Println(err)
@@ -113,6 +114,11 @@ func mainWithRc() int {
113114
}
114115
}
115116

117+
if err == nil {
118+
cmho := ibmmq.NewMQCMHO()
119+
mh, err = qMgrObject.CrtMH(cmho)
120+
}
121+
116122
if err == nil {
117123
// The GET/MQCB requires control structures, the Message Descriptor (MQMD)
118124
// and Get Options (MQGMO). Create those with default values.
@@ -128,6 +134,9 @@ func mainWithRc() int {
128134
gmo.Options |= ibmmq.MQGMO_WAIT
129135
gmo.WaitInterval = 3 * 1000 // The WaitInterval is in milliseconds
130136

137+
gmo.Options |= ibmmq.MQGMO_PROPERTIES_IN_HANDLE
138+
gmo.MsgHandle = mh
139+
131140
// The MQCBD structure is used to specify the function to be invoked
132141
// when a message arrives on a queue
133142
cbd := ibmmq.NewMQCBD()

0 commit comments

Comments
 (0)