1
1
# IBM MQ JMS Spring Components
2
2
3
- This repository contains code to help to provide Spring developers with easy configuration of the IBM MQ JMS package.
3
+ This repository contains code to help to provide Spring developers with easy configuration and testing of the IBM MQ JMS
4
+ package.
4
5
5
6
The library contains:
6
7
7
8
- ` mq-jms-spring-boot-starter ` for [ Spring Boot] ( https://projects.spring.io/spring-boot/ ) applications
9
+ - ` mq-jms-spring-testcontainer ` for testing Spring Boot applications
10
+ - ` mq-java-testcontainer ` for integration with the [ Testcontainers] ( https://testcontainers.org ) project
8
11
9
- NOTE: Spring Boot 2 has now reached its end of non-commercial service life.
10
- So version 2.7.18 is the last update based on Spring 2. Further updates will
11
- follow the Spring 3 path only. If you want to continue to use Spring 2 with future versions of the MQ jars,
12
- then overriding the version inherited from the mq-jms-spring-boot in your parent pom.xml should be possible.
13
- However, this would not give easy access via configuration to any new features available in the MQ client.
12
+ NOTE: Spring Boot 2 has now reached its end of non-commercial service life. So version 2.7.18 is the last update based
13
+ on Spring 2. Further updates will follow the Spring 3 path only. If you want to continue to use Spring 2 with future
14
+ versions of the MQ jars, then overriding the version inherited from the mq-jms-spring-boot in your parent pom.xml should
15
+ be possible. However, this would not give easy access via configuration to any new features available in the MQ client.
16
+
17
+ NOTE: Spring Boot 4 is under development planned for release later in 2025. While this package does not currently do
18
+ anything specific for Boot 4, the pieces are already in place to be able to build against it once it is available.
14
19
15
20
## Installation and Usage
16
21
@@ -49,22 +54,28 @@ Maven:
49
54
** Note** This repository and the corresponding Maven Central artifacts requires Spring Boot 3. Maven
50
55
Central continues to provide older versions that work with Spring Boot 2.
51
56
57
+ ## Testcontainers
58
+ For testing Spring Boot applications, you may need to provision a queue manager as part of the process. This can be
59
+ done by using the Testcontainers framework. For more information about the MQ package, see [ here] ( README_TESTCONTAINERS.md ) .
60
+ Also look at the ` samples/s5 ` directory for a demonstration.
61
+
52
62
## Design Approach
53
63
54
64
The approach taken here is to follow the model for JMS applications shown in the
55
65
[ Spring Getting Started Guide for JMS] ( https://spring.io/guides/gs/messaging-jms/ ) . That in turn
56
66
is based on using the [ JmsTemplate Framework] ( https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#jms-jmstemplate )
57
67
58
- Some simple example programs using Spring Boot and JMS interfaces can be found in the samples directory. The RUNME.sh program in
59
- each subdirectory compiles and executes it. The application.properties files in that tree may need modification for your environment.
68
+ Some simple example programs using Spring Boot and JMS interfaces can be found in the samples directory. The RUNME.sh
69
+ program in each subdirectory compiles and executes it. The _ application.properties_ or _ application.yml_ files in that
70
+ tree may need modification for your environment.
60
71
61
72
Essentially what gets configured from this package are a ConnectionFactory which Spring's JmsTemplate implementation
62
73
exploits to provide a simpler interface, and a MessageListener.
63
74
64
75
## Getting Started
65
76
66
77
To get started quickly, you can use the default configuration settings in this package along with the
67
- IBM MQ for Developers container which runs the server processes.
78
+ IBM MQ Advanced for Developers container which runs the server processes.
68
79
69
80
### Default Configuration
70
81
@@ -80,7 +91,7 @@ This script will run the container on a Linux system.
80
91
--publish 1414:1414 \
81
92
--publish 9443:9443 \
82
93
--detach \
83
- ibmcom /mq
94
+ icr.io:ibm-messaging /mq:latest
84
95
85
96
The default attributes are
86
97
@@ -90,7 +101,7 @@ The default attributes are
90
101
ibm.mq.user=
91
102
ibm.mq.password=
92
103
93
- ### Connection security
104
+ ### Authentication with passwords
94
105
95
106
The default userid and password have been removed from this package, as the corresponding default configuration has been
96
107
removed from the MQ Developer images. Authentication must now be explicitly defined both for the queue manager, and for
@@ -106,11 +117,27 @@ must now set the `ibm.mq.user` and `ibm.mq.password` attribute.
106
117
Configuration of secure connections with TLS are discussed below.
107
118
108
119
109
- #### JWT Tokens
120
+ ### Authentication with JWT tokens
110
121
If the queue manager has been configured to authenticate applications based on JWT tokens, then those tokens can be
111
122
provided through the JMS layer.
112
123
113
- To use this, you can either set ` ibm.mq.token `
124
+ #### MQ-retrieved tokens
125
+ The JMS client code can generate and retrieve tokens from a server automatically, without needing the application to
126
+ explicitly contact the token server itself. The application needs configuration of how to contact the server, but then
127
+ the communication to the token server (eg Keycloak) is handled automatically. The ` ibm.mq.tokenServer ` section of the
128
+ configuration provides the route and authentication mechanism for the server.
129
+
130
+ ** Note:** There are some current constraints on how this mechanism works, with respect to the HTTPS connection that needs
131
+ to be made to the token server:
132
+ * The keystore/truststore uses process-wide environment variables that might affect other components of the application
133
+ if they also use the ` javax.net.ssl ` properties.
134
+ * The keystore/truststore must be local JKS files, not embedded in the jar and its classpath
135
+ * The ` validateCertificatePolicy ` setting cannot be used to always trust a token server's certificate
136
+
137
+
138
+ #### Explicity-provided tokens
139
+ Having the token provided directly in the application configuration continues to work, but is not the recommended
140
+ approach, now that the MQ JMS layer can do that retrieval itself. To use this method, you can either set ` ibm.mq.token `
114
141
or the password to the token. If you use the ` password ` attribute, then the ` user ` must also be set to the empty value
115
142
(which is now the default anyway).
116
143
@@ -196,9 +223,31 @@ Spring Boot will then create a ConnectionFactory that can then be used to intera
196
223
197
224
The ` reconnect ` option was previously named ` defaultReconnect ` but both names work in the configuration.
198
225
226
+ For contacting a Token Server, these options define its address and authentication. All three properties
227
+ have to be supplied if you are using this authentication mechanism:
228
+
229
+ | Option (ibm.mq.tokenServer) | Description |
230
+ | -----------------------------| ------------------------------------------------------------------------------ |
231
+ | endpoint | URL pointing at the token server (eg https://my.keycloak.server) |
232
+ | clientId | The ClientId for authentication to the server (unrelated to ibm.mq.clientId) |
233
+ | clientSecret | The ClientSecret for authentication to the server |
234
+
199
235
#### TLS related options
200
236
201
- The following options all default to null, but may be used to assist with configuring TLS
237
+ The preferred approach for setting the key/truststores is available from Spring 3.1, which introduced the
238
+ concept of "SSL Bundles". This makes it possible to have different SSL configurations - keystores, truststores etc - for
239
+ different components executing in the same Spring-managed process. See
240
+ [ here] ( https://spring.io/blog/2023/06/07/securing-spring-boot-applications-with-ssl ) for a description of the options
241
+ available. Each bundle has an identifier with the ` spring.ssl.bundle.jks.<key> ` tree of options. The key can be
242
+ specified for this package with ` ibm.mq.sslBundle ` which then uses the Spring elements to create the connection
243
+ configuration. The default value for this key is empty, meaning that ` SSLBundles ` will not be used; the global SSL
244
+ configuration is used instead. However the ` ibm.mq.jks ` properties are now marked as deprecated.
245
+
246
+ | Option (ibm.mq) | Description |
247
+ | -------------------- | ---------------------------------------------------------------------------- |
248
+ | sslBundle | Spring Boot option (from 3.1) for granular certificate configuration |
249
+
250
+ The following options all default to null, but may also be used to assist with configuring TLS
202
251
203
252
| Option (ibm.mq) | Description |
204
253
| -------------------- | ------------------------------------------------------------------------------- |
226
275
| keyStore | Where is the keystore with a personal key and certificate |
227
276
| keyStorePassword | Password for the keyStore |
228
277
229
- These JKS options are an alternative to setting the ` javax.net.ssl ` system properties, usually done on the command line.
230
-
231
- An alternative preferred approach for setting the key/truststores is available from Spring 3.1, which introduced the
232
- concept of "SSL Bundles". This makes it possible to have different SSL configurations - keystores, truststores etc - for
233
- different components executing in the same Spring-managed process. See
234
- [ here] ( https://spring.io/blog/2023/06/07/securing-spring-boot-applications-with-ssl ) for a description of the options
235
- available. Each bundle has an identifier with the ` spring.ssl.bundle.jks.<key> ` tree of options. The key can be
236
- specified for this package with ` ibm.mq.sslBundle ` which then uses the Spring elements to create the connection
237
- configuration. The default value for this key is empty, meaning that ` SSLBundles ` will not be used; the global SSL
238
- configuration is used instead. However the ` ibm.mq.jks ` properties are now marked as deprecated.
239
-
240
- | Option (ibm.mq) | Description |
241
- | -------------------- | ---------------------------------------------------------------------------- |
242
- | sslBundle | Spring Boot option (from 3.1) for granular certificate configuration |
243
-
244
- To achieve the same effect with Spring 2.x, you could use your own code to create an ` SSLSocketFactory ` object
245
- which can be applied to the MQ Connection Factory in a ` customise ` method before the CF is invoked.
246
-
247
- Spring Boot 3.4.0 changed how the sslBundles are loaded. If you have a simple file name such as ` location: "key.jks" `
248
- and there is an exception saying that the file cannot be found, then change the property to ` location: "file:key.jks" ` .
249
- This regression has been fixed in Spring Boot 3.4.2, so you should not see this problem.
278
+ These deprecated JKS options are an alternative to setting the ` javax.net.ssl ` system properties, usually done on the
279
+ command line. They are not used if you have set the ` sslBundle ` property.
250
280
251
281
#### Caching connection factory options
252
282
@@ -344,8 +374,13 @@ more details.
344
374
However this package also enables some simple use of JNDI for Connection definitions (but not Destinations, as they are
345
375
still always handled by the core Spring classes).
346
376
347
- You can set the ` ibm.mq.jndi.providerUrl ` and ` ibm.mq.jndi.providerContextFactory ` attributes to define how the lookup
348
- is to be carried out. For example,
377
+ | Option (ibm.mq.jndi) | Description |
378
+ | -----------------------| ------------------------------------------- |
379
+ | providerUrl | Location of the directory |
380
+ | providerContextFactory | Class implementing the directory |
381
+ | additionalProperties | For further configuration - class-dependent |
382
+
383
+ For example,
349
384
350
385
```
351
386
ibm.mq.jndi.providerUrl=file:///home/username/mqjms/jndi
0 commit comments