Skip to content

Commit

Permalink
Update to latest Spring dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ibmmqmet committed Sep 23, 2022
1 parent 92b1516 commit 022e32a
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Newest updates are at the top of this file

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

## 2.7.2 and 0.3.0-M4 (2022-07-22)
- Update dependencies to Spring Boot 2.7.2/3.0.0-M4
Expand Down
1 change: 1 addition & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ the available properties.
* s1 - The simplest example that creates two connections to MQ: one to put a message,
and the other to act as a JMSListener that retrieves the message.
* s2 - Demonstrates use of local transactional control to commit and rollback changes
* s2.tls - Identical to s2 but with information about using a TLS-enabled connection
* s3 - A request/reply program, with both the requester and responder in the same application.
The responder side shows how transactions can be controlled within a JMSListener.
* s3.jms3 - Identical to s3 but changed to use the Jakarta packages and corresponding
Expand Down
2 changes: 1 addition & 1 deletion samples/s1/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'java'
apply plugin: 'org.springframework.boot'

// The designated version should match the current version in the root of the repo
ext.starterVersion = '2.7.2'
ext.starterVersion = '2.7.4'

// The local, flatDir configuration lets us use a modified version from
// this repository without needing it released via maven
Expand Down
35 changes: 35 additions & 0 deletions samples/s2.tls/RUNME.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This script compiles and runs the sample program in this directory.
#
# The program puts a single message to the DEV.QUEUE.1 queue and tries to
# retrieve it via a JMS Listener.
#
# It uses a TLS-enabled channel with the configuration partly
# in the application.properties file, and partly in the build.gradle
# file where system properties are set to point at keystores.
#
# In a standalone execution environment, those properties will be
# set with -D options on the java command line. Or you might prefer
# to use System.setProperty() in your application code as one way to
# manage the password if it is needed for the jks access. Or you might
# use alternative Spring solutions for configuration properties.
#
# You may need to modify the application.properties file to get it to
# connect to your queue manager.
#
# For the simple requirement of one-way authentication here, we have extracted
# the queue manager's public certificate into qm1.arm. And then imported it (I used
# strmqikm but command line tools could have been instead) into key.jks.

###### Cleanup from previous runs
# Kill any old instances of the application
ps -ef|grep gradle | grep sample2.Application | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1
# and try to clear the queue (assuming it's a local queue manager)
echo "CLEAR QLOCAL(DEV.QUEUE.1)" | runmqsc -e QM1 >/dev/null 2>&1
######
#
curdir=`pwd`

# Now run the program. Build using the gradle wrapper in parent directory
cd ../..

./gradlew -p samples/s2.tls bootRun
37 changes: 37 additions & 0 deletions samples/s2.tls/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
}
}


apply plugin: 'java'
apply plugin: 'org.springframework.boot'

// The designated version should match the current version in the root of the repo
ext.starterVersion = '2.7.4'

// The local, flatDir configuration lets us use a modified version from
// this repository without needing it released via maven
repositories {
flatDir() {
dirs '../../mq-jms-spring-boot-starter'
}
mavenLocal()
mavenCentral()
}

dependencies {
implementation(group:"com.ibm.mq", name:"mq-jms-spring-boot-starter", version:starterVersion)
}

bootRun {
systemProperty('javax.net.ssl.trustStore','key.jks')
systemProperty('javax.net.ssl.trustStorePassword','passw0rd')
systemProperty('javax.net.ssl.keyStore','key.jks')
systemProperty('javax.net.ssl.keyStorePassword','passw0rd')
}
Binary file added samples/s2.tls/key.jks
Binary file not shown.
17 changes: 17 additions & 0 deletions samples/s2.tls/qm1.arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE-----
MIIDKTCCAhGgAwIBAgIIc4omnV2OD6wwDQYJKoZIhvcNAQENBQAwKjEMMAoGA1UECxMDSUJNMRow
GAYDVQQDExFpYm13ZWJzcGhlcmVtcXFtMTAeFw0yMjA3MDUwODU5MzVaFw0yMzA3MDYwODU5MzVa
MCoxDDAKBgNVBAsTA0lCTTEaMBgGA1UEAxMRaWJtd2Vic3BoZXJlbXFxbTEwggEiMA0GCSqGSIb3
DQEBAQUAA4IBDwAwggEKAoIBAQCbHyyOPAE7olEnh5+PY5qAx865gmP8VRwlAVWAhh3PMbbpDgNj
8/AEX76MrTZlKD0a7sbHh7EDgIpmbRtu1x4hK930qInFeBRjvECh7/dFD9YTMfI501cgk1snAze7
5d4AXOUJRq54HvwHWCMWNpcetBtc0wmRZtMPE+hLFgli3FX8ZZ5vBWSb2XViGvldm18LZWPPrRLA
3ytGoluW2X1+ZlMJo9EJComL1EgbxZifBdyKT2rFSyXnhW4a5zF4tkHJ7LEd9pFJhgEZHdJQrKe/
UtHZl8pOlLuYq4TkalLsv9W1eJMKO/K7irqnsCkA58A3zN+r7F4Ge4mjWG3NqK1nAgMBAAGjUzBR
MA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFHDnp4R/w1RJ0VddCQS12SGIerpOMB8GA1UdIwQY
MBaAFHDnp4R/w1RJ0VddCQS12SGIerpOMA0GCSqGSIb3DQEBDQUAA4IBAQBdT120rCTnz1L77FEQ
o03GwwH/rp7nDT5hCH8lwIHpiHe9yXxuwqkyq8J89H+7UBlzBKHTiAuax3YqHWg169y8utC1kMvr
/IThpTioESVtc7KnTWeH9aF/rBLYpQZr3dDoZM7VwMD7W851U/3+JyZh+VvZawc1pqbYA1SXfhkn
ABOuHUDMZTbQWgyQ9lfG0HYf0SzS/zCAc3ZiAhiB/zp48DJ2fwKnceuoEhgJM/PZCSjB9NBCKQIT
9R85snkOYKu2hxH00zMq7XXMqKTKBXdvP6Zny5yh9WUfrJrcxg35tKQtq/XBKo7BwFVe/hIcDez0
SBu6QOL2a/tBKKv3LQcB
-----END CERTIFICATE-----
16 changes: 16 additions & 0 deletions samples/s2.tls/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright © 2017, 2020 IBM Corp. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/


rootProject.name = 'mq-jms-spring-sample2'
101 changes: 101 additions & 0 deletions samples/s2.tls/src/main/java/sample2/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright © 2017, 2020 IBM Corp. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

// An example of using the Spring Boot JmsTemplate in conjunction with local transactions
//
// This program connects to a queue manager, puts a message and then tries to move the message
// from one queue to another, but choosing to fail that movement through a rollback of the
// transaction. Despite using a Spring TransactionManager object, there is no distributed (XA or
// two-phase) transaction created.
//
// An equivalent MQI program would have this logic:
// MQPUT(q1) with SYNCPOINT
// MQCMIT
// MQGET(q1) with SYNCPOINT
// MQPUT(q2) with SYNCPOINT
// MQBACK

package sample2;

import java.util.Date;

import javax.jms.Message;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.connection.JmsTransactionManager;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@EnableJms
@EnableTransactionManagement
public class Application {

static final String qName1 = "DEV.QUEUE.1"; // A queue from the default MQ Developer container config
static final String qName2 = "DEV.QUEUE.2"; // Another queue from the default MQ Developer container config

public static void main(String[] args) {

// Launch the application
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);

// Create a transaction manager object that will be used to control commit/rollback of operations.
JmsTransactionManager tm = new JmsTransactionManager();

printStarted();

// Create the JMS Template object to control connections and sessions.
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);

// Associate the connection factory with the transaction manager
tm.setConnectionFactory(jmsTemplate.getConnectionFactory());

// This starts a new transaction scope. "null" can be used to get a default transaction model
TransactionStatus status = tm.getTransaction(null);

// Create a single message with a timestamp
String outMsg = "Hello from IBM MQ at " + new Date();

// The default SimpleMessageConverter class will be called and turn a String
// into a JMS TextMessage which we send to qName1. This operation will be made
// part of the transaction that we initiated.
jmsTemplate.convertAndSend(qName1, outMsg);

// Commit the transaction so the message is now visible
tm.commit(status);

// But now we're going to start a new transaction to hold multiple operations.
status = tm.getTransaction(null);
// Read it from the queue where we just put it, and then send it straight on to
// a different queue
Message inMsg = jmsTemplate.receive(qName1);
jmsTemplate.convertAndSend(qName2, inMsg);
// This time we decide to rollback the transaction so the receive() and send() are
// reverted. We end up with the message still on qName1.
tm.rollback(status);

System.out.println("Done.");
}

static void printStarted() {
System.out.println();
System.out.println("========================================");
System.out.println("MQ JMS Transaction Sample started.");
System.out.println("========================================");
}
}
11 changes: 11 additions & 0 deletions samples/s2.tls/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

ibm.mq.queueManager=QM1
ibm.mq.channel=SYSTEM.SSL.SVRCONN.1
ibm.mq.connName=localhost(1414)
ibm.mq.sslCipherSpec=ANY_TLS12_OR_HIGHER

# Change the following lines as necessary. Set the ibm.mq.user
# property to an empty string to send no authentication request.
#ibm.mq.user=mqguest
#ibm.mq.user=
#ibm.mq.password=passw0rd
2 changes: 1 addition & 1 deletion samples/s2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'java'
apply plugin: 'org.springframework.boot'

// The designated version should match the current version in the root of the repo
ext.starterVersion = '2.7.2'
ext.starterVersion = '2.7.4'

// The local, flatDir configuration lets us use a modified version from
// this repository without needing it released via maven
Expand Down
2 changes: 1 addition & 1 deletion samples/s3.jms3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'java'
apply plugin: 'org.springframework.boot'

// The designated version should match the current version in the root of the repo
ext.starterVersion = '0.3.0-M4'
ext.starterVersion = '0.3.0-M5'


// The local, flatDir configuration lets us use a modified version from
Expand Down
2 changes: 1 addition & 1 deletion samples/s3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'java'
apply plugin: 'org.springframework.boot'

// The designated version should match the current version in the root of the repo
ext.starterVersion = '2.7.2'
ext.starterVersion = '2.7.4'

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

0 comments on commit 022e32a

Please sign in to comment.