Skip to content

Commit 022e32a

Browse files
committed
Update to latest Spring dependencies
1 parent 92b1516 commit 022e32a

13 files changed

Lines changed: 223 additions & 4 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Newest updates are at the top of this file
33

44
## 2.7.4 and 0.3.0-M6 (2022-09-23)
55
- Update dependencies to Spring Boot 2.7.4/3.0.0-M5
6+
- Add a TLS-enabled sample
67

78
## 2.7.2 and 0.3.0-M4 (2022-07-22)
89
- Update dependencies to Spring Boot 2.7.2/3.0.0-M4

samples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ the available properties.
1111
* s1 - The simplest example that creates two connections to MQ: one to put a message,
1212
and the other to act as a JMSListener that retrieves the message.
1313
* s2 - Demonstrates use of local transactional control to commit and rollback changes
14+
* s2.tls - Identical to s2 but with information about using a TLS-enabled connection
1415
* s3 - A request/reply program, with both the requester and responder in the same application.
1516
The responder side shows how transactions can be controlled within a JMSListener.
1617
* s3.jms3 - Identical to s3 but changed to use the Jakarta packages and corresponding

samples/s1/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ apply plugin: 'java'
1313
apply plugin: 'org.springframework.boot'
1414

1515
// The designated version should match the current version in the root of the repo
16-
ext.starterVersion = '2.7.2'
16+
ext.starterVersion = '2.7.4'
1717

1818
// The local, flatDir configuration lets us use a modified version from
1919
// this repository without needing it released via maven

samples/s2.tls/RUNME.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This script compiles and runs the sample program in this directory.
2+
#
3+
# The program puts a single message to the DEV.QUEUE.1 queue and tries to
4+
# retrieve it via a JMS Listener.
5+
#
6+
# It uses a TLS-enabled channel with the configuration partly
7+
# in the application.properties file, and partly in the build.gradle
8+
# file where system properties are set to point at keystores.
9+
#
10+
# In a standalone execution environment, those properties will be
11+
# set with -D options on the java command line. Or you might prefer
12+
# to use System.setProperty() in your application code as one way to
13+
# manage the password if it is needed for the jks access. Or you might
14+
# use alternative Spring solutions for configuration properties.
15+
#
16+
# You may need to modify the application.properties file to get it to
17+
# connect to your queue manager.
18+
#
19+
# For the simple requirement of one-way authentication here, we have extracted
20+
# the queue manager's public certificate into qm1.arm. And then imported it (I used
21+
# strmqikm but command line tools could have been instead) into key.jks.
22+
23+
###### Cleanup from previous runs
24+
# Kill any old instances of the application
25+
ps -ef|grep gradle | grep sample2.Application | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1
26+
# and try to clear the queue (assuming it's a local queue manager)
27+
echo "CLEAR QLOCAL(DEV.QUEUE.1)" | runmqsc -e QM1 >/dev/null 2>&1
28+
######
29+
#
30+
curdir=`pwd`
31+
32+
# Now run the program. Build using the gradle wrapper in parent directory
33+
cd ../..
34+
35+
./gradlew -p samples/s2.tls bootRun

samples/s2.tls/build.gradle

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
buildscript {
3+
repositories {
4+
mavenCentral()
5+
}
6+
dependencies {
7+
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
8+
}
9+
}
10+
11+
12+
apply plugin: 'java'
13+
apply plugin: 'org.springframework.boot'
14+
15+
// The designated version should match the current version in the root of the repo
16+
ext.starterVersion = '2.7.4'
17+
18+
// The local, flatDir configuration lets us use a modified version from
19+
// this repository without needing it released via maven
20+
repositories {
21+
flatDir() {
22+
dirs '../../mq-jms-spring-boot-starter'
23+
}
24+
mavenLocal()
25+
mavenCentral()
26+
}
27+
28+
dependencies {
29+
implementation(group:"com.ibm.mq", name:"mq-jms-spring-boot-starter", version:starterVersion)
30+
}
31+
32+
bootRun {
33+
systemProperty('javax.net.ssl.trustStore','key.jks')
34+
systemProperty('javax.net.ssl.trustStorePassword','passw0rd')
35+
systemProperty('javax.net.ssl.keyStore','key.jks')
36+
systemProperty('javax.net.ssl.keyStorePassword','passw0rd')
37+
}

samples/s2.tls/key.jks

885 Bytes
Binary file not shown.

samples/s2.tls/qm1.arm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDKTCCAhGgAwIBAgIIc4omnV2OD6wwDQYJKoZIhvcNAQENBQAwKjEMMAoGA1UECxMDSUJNMRow
3+
GAYDVQQDExFpYm13ZWJzcGhlcmVtcXFtMTAeFw0yMjA3MDUwODU5MzVaFw0yMzA3MDYwODU5MzVa
4+
MCoxDDAKBgNVBAsTA0lCTTEaMBgGA1UEAxMRaWJtd2Vic3BoZXJlbXFxbTEwggEiMA0GCSqGSIb3
5+
DQEBAQUAA4IBDwAwggEKAoIBAQCbHyyOPAE7olEnh5+PY5qAx865gmP8VRwlAVWAhh3PMbbpDgNj
6+
8/AEX76MrTZlKD0a7sbHh7EDgIpmbRtu1x4hK930qInFeBRjvECh7/dFD9YTMfI501cgk1snAze7
7+
5d4AXOUJRq54HvwHWCMWNpcetBtc0wmRZtMPE+hLFgli3FX8ZZ5vBWSb2XViGvldm18LZWPPrRLA
8+
3ytGoluW2X1+ZlMJo9EJComL1EgbxZifBdyKT2rFSyXnhW4a5zF4tkHJ7LEd9pFJhgEZHdJQrKe/
9+
UtHZl8pOlLuYq4TkalLsv9W1eJMKO/K7irqnsCkA58A3zN+r7F4Ge4mjWG3NqK1nAgMBAAGjUzBR
10+
MA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFHDnp4R/w1RJ0VddCQS12SGIerpOMB8GA1UdIwQY
11+
MBaAFHDnp4R/w1RJ0VddCQS12SGIerpOMA0GCSqGSIb3DQEBDQUAA4IBAQBdT120rCTnz1L77FEQ
12+
o03GwwH/rp7nDT5hCH8lwIHpiHe9yXxuwqkyq8J89H+7UBlzBKHTiAuax3YqHWg169y8utC1kMvr
13+
/IThpTioESVtc7KnTWeH9aF/rBLYpQZr3dDoZM7VwMD7W851U/3+JyZh+VvZawc1pqbYA1SXfhkn
14+
ABOuHUDMZTbQWgyQ9lfG0HYf0SzS/zCAc3ZiAhiB/zp48DJ2fwKnceuoEhgJM/PZCSjB9NBCKQIT
15+
9R85snkOYKu2hxH00zMq7XXMqKTKBXdvP6Zny5yh9WUfrJrcxg35tKQtq/XBKo7BwFVe/hIcDez0
16+
SBu6QOL2a/tBKKv3LQcB
17+
-----END CERTIFICATE-----

samples/s2.tls/settings.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright © 2017, 2020 IBM Corp. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
14+
15+
16+
rootProject.name = 'mq-jms-spring-sample2'
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright © 2017, 2020 IBM Corp. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
14+
15+
// An example of using the Spring Boot JmsTemplate in conjunction with local transactions
16+
//
17+
// This program connects to a queue manager, puts a message and then tries to move the message
18+
// from one queue to another, but choosing to fail that movement through a rollback of the
19+
// transaction. Despite using a Spring TransactionManager object, there is no distributed (XA or
20+
// two-phase) transaction created.
21+
//
22+
// An equivalent MQI program would have this logic:
23+
// MQPUT(q1) with SYNCPOINT
24+
// MQCMIT
25+
// MQGET(q1) with SYNCPOINT
26+
// MQPUT(q2) with SYNCPOINT
27+
// MQBACK
28+
29+
package sample2;
30+
31+
import java.util.Date;
32+
33+
import javax.jms.Message;
34+
35+
import org.springframework.boot.SpringApplication;
36+
import org.springframework.boot.autoconfigure.SpringBootApplication;
37+
import org.springframework.context.ConfigurableApplicationContext;
38+
import org.springframework.jms.annotation.EnableJms;
39+
import org.springframework.jms.connection.JmsTransactionManager;
40+
import org.springframework.jms.core.JmsTemplate;
41+
import org.springframework.transaction.TransactionStatus;
42+
import org.springframework.transaction.annotation.EnableTransactionManagement;
43+
44+
@SpringBootApplication
45+
@EnableJms
46+
@EnableTransactionManagement
47+
public class Application {
48+
49+
static final String qName1 = "DEV.QUEUE.1"; // A queue from the default MQ Developer container config
50+
static final String qName2 = "DEV.QUEUE.2"; // Another queue from the default MQ Developer container config
51+
52+
public static void main(String[] args) {
53+
54+
// Launch the application
55+
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
56+
57+
// Create a transaction manager object that will be used to control commit/rollback of operations.
58+
JmsTransactionManager tm = new JmsTransactionManager();
59+
60+
printStarted();
61+
62+
// Create the JMS Template object to control connections and sessions.
63+
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
64+
65+
// Associate the connection factory with the transaction manager
66+
tm.setConnectionFactory(jmsTemplate.getConnectionFactory());
67+
68+
// This starts a new transaction scope. "null" can be used to get a default transaction model
69+
TransactionStatus status = tm.getTransaction(null);
70+
71+
// Create a single message with a timestamp
72+
String outMsg = "Hello from IBM MQ at " + new Date();
73+
74+
// The default SimpleMessageConverter class will be called and turn a String
75+
// into a JMS TextMessage which we send to qName1. This operation will be made
76+
// part of the transaction that we initiated.
77+
jmsTemplate.convertAndSend(qName1, outMsg);
78+
79+
// Commit the transaction so the message is now visible
80+
tm.commit(status);
81+
82+
// But now we're going to start a new transaction to hold multiple operations.
83+
status = tm.getTransaction(null);
84+
// Read it from the queue where we just put it, and then send it straight on to
85+
// a different queue
86+
Message inMsg = jmsTemplate.receive(qName1);
87+
jmsTemplate.convertAndSend(qName2, inMsg);
88+
// This time we decide to rollback the transaction so the receive() and send() are
89+
// reverted. We end up with the message still on qName1.
90+
tm.rollback(status);
91+
92+
System.out.println("Done.");
93+
}
94+
95+
static void printStarted() {
96+
System.out.println();
97+
System.out.println("========================================");
98+
System.out.println("MQ JMS Transaction Sample started.");
99+
System.out.println("========================================");
100+
}
101+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
ibm.mq.queueManager=QM1
3+
ibm.mq.channel=SYSTEM.SSL.SVRCONN.1
4+
ibm.mq.connName=localhost(1414)
5+
ibm.mq.sslCipherSpec=ANY_TLS12_OR_HIGHER
6+
7+
# Change the following lines as necessary. Set the ibm.mq.user
8+
# property to an empty string to send no authentication request.
9+
#ibm.mq.user=mqguest
10+
#ibm.mq.user=
11+
#ibm.mq.password=passw0rd

0 commit comments

Comments
 (0)