-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to latest Spring dependencies
- Loading branch information
Showing
13 changed files
with
223 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("========================================"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters