Skip to content

Commit f6f2219

Browse files
Added MQ Connection Options to allow configuring of connection
1 parent 044c73a commit f6f2219

File tree

3 files changed

+59
-14
lines changed

3 files changed

+59
-14
lines changed

go.sum

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
22
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/ibm-messaging/mq-golang v1.0.1-0.20190820103725-19b946c185a8 h1:kUwSXeftVen12FRnShG+Ykhb2Kd6Cd/DbpWwbYal7j0=
4-
github.com/ibm-messaging/mq-golang v1.0.1-0.20190820103725-19b946c185a8/go.mod h1:qjsZDb7m1oKnbPeDma2JVJTKgyCA91I4bcJ1qHY+gcA=
5-
github.com/ibm-messaging/mq-golang v3.0.0+incompatible h1:Yc3c8emAyveT54uNDRMkgvS+EBAHeLNWHkc3hk5x+IY=
6-
github.com/ibm-messaging/mq-golang v3.0.0+incompatible/go.mod h1:qjsZDb7m1oKnbPeDma2JVJTKgyCA91I4bcJ1qHY+gcA=
7-
github.com/ibm-messaging/mq-golang/v5 v5.0.0 h1:9J8bsDoCo60rbSgB7ZAURPG3L5Kpr+F8dYNOwQ7Qnnk=
8-
github.com/ibm-messaging/mq-golang/v5 v5.0.0/go.mod h1:ywCwmYbJOU/E0rl+z4GiNoxVMty68O+LVO39a1VMXrE=
9-
github.com/ibm-messaging/mq-golang/v5 v5.1.2 h1:u0e1Vce2TNqJpH088vF77rDMsnMRWnGaOIlxZo4DMZc=
10-
github.com/ibm-messaging/mq-golang/v5 v5.1.2/go.mod h1:ywCwmYbJOU/E0rl+z4GiNoxVMty68O+LVO39a1VMXrE=
11-
github.com/ibm-messaging/mq-golang/v5 v5.1.3 h1:B1Xfk1jMulmDfPf3jH2Dh9nnyEkaqfI1FvTHt4pFza4=
12-
github.com/ibm-messaging/mq-golang/v5 v5.1.3/go.mod h1:ywCwmYbJOU/E0rl+z4GiNoxVMty68O+LVO39a1VMXrE=
133
github.com/ibm-messaging/mq-golang/v5 v5.2.4 h1:Sn+XpnhlTzBs/xPRAHzSx+YjCdxhmzJu5bv4pWTWu/I=
144
github.com/ibm-messaging/mq-golang/v5 v5.2.4/go.mod h1:ywCwmYbJOU/E0rl+z4GiNoxVMty68O+LVO39a1VMXrE=
155
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
166
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
17-
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
187
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
198
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
209
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=

mq_connection_options_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) IBM Corporation 2019
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*/
10+
package main
11+
12+
import (
13+
"github.com/ibm-messaging/mq-golang/v5/ibmmq"
14+
"testing"
15+
16+
"github.com/ibm-messaging/mq-golang-jms20/mqjms"
17+
"github.com/stretchr/testify/assert"
18+
)
19+
20+
func TestMQConnectionOptions(t *testing.T) {
21+
t.Run("MaxMsgLength", func(t *testing.T) {
22+
// Loads CF parameters from connection_info.json and applicationApiKey.json in the Downloads directory
23+
cf, cfErr := mqjms.CreateConnectionFactoryFromDefaultJSONFiles()
24+
assert.Nil(t, cfErr)
25+
26+
// Ensure that the options were applied when setting connection options on Context creation
27+
msg := "options were not applied"
28+
context, ctxErr := cf.CreateContext(
29+
mqjms.WithMaxMsgLength(2000),
30+
func(cno *ibmmq.MQCNO) {
31+
assert.Equal(t, 2000, cno.ClientConn.MaxMsgLength)
32+
msg = "options applied"
33+
},
34+
)
35+
assert.Nil(t, ctxErr)
36+
37+
if context != nil {
38+
defer context.Close()
39+
}
40+
41+
assert.Equal(t, "options applied", msg)
42+
})
43+
}

mqjms/ConnectionFactoryImpl.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ type ConnectionFactoryImpl struct {
5959

6060
// CreateContext implements the JMS method to create a connection to an IBM MQ
6161
// queue manager.
62-
func (cf ConnectionFactoryImpl) CreateContext() (jms20subset.JMSContext, jms20subset.JMSException) {
63-
return cf.CreateContextWithSessionMode(jms20subset.JMSContextAUTOACKNOWLEDGE)
62+
func (cf ConnectionFactoryImpl) CreateContext(mqos ...MQOptions) (jms20subset.JMSContext, jms20subset.JMSException) {
63+
return cf.CreateContextWithSessionMode(jms20subset.JMSContextAUTOACKNOWLEDGE, mqos...)
6464
}
6565

6666
// CreateContextWithSessionMode implements the JMS method to create a connection to an IBM MQ
6767
// queue manager using the specified session mode.
68-
func (cf ConnectionFactoryImpl) CreateContextWithSessionMode(sessionMode int) (jms20subset.JMSContext, jms20subset.JMSException) {
68+
func (cf ConnectionFactoryImpl) CreateContextWithSessionMode(sessionMode int, mqos ...MQOptions) (jms20subset.JMSContext, jms20subset.JMSException) {
6969

7070
// Allocate the internal structures required to create an connection to IBM MQ.
7171
cno := ibmmq.NewMQCNO()
@@ -131,6 +131,11 @@ func (cf ConnectionFactoryImpl) CreateContextWithSessionMode(sessionMode int) (j
131131

132132
}
133133

134+
// Apply options
135+
for _, mqo := range mqos {
136+
mqo(cno)
137+
}
138+
134139
var ctx jms20subset.JMSContext
135140
var retErr jms20subset.JMSException
136141

@@ -170,3 +175,11 @@ func (cf ConnectionFactoryImpl) CreateContextWithSessionMode(sessionMode int) (j
170175
return ctx, retErr
171176

172177
}
178+
179+
type MQOptions func(cno *ibmmq.MQCNO)
180+
181+
func WithMaxMsgLength(maxMsgLength int32) MQOptions {
182+
return func(cno *ibmmq.MQCNO) {
183+
cno.ClientConn.MaxMsgLength = maxMsgLength
184+
}
185+
}

0 commit comments

Comments
 (0)