Skip to content

Commit

Permalink
Update dependencies for MQ 9.2.1, Spring Boot 2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ibmmqmet committed Dec 8, 2020
1 parent f958103 commit 3a5e1b0
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
Newest updates are at the top of this file

## 2.4.0 (2020-12-04)
- Update dependencies to Spring Boot 2.4.0
- Update dependencies to MQ 9.2.1
- Move original sample to a subdirectory and add another sample showing transactions

## 2.3.5 (2020-10-30)
- Update KnowledgeCenter URLs to refer to 'latest' version
- Update dependencies to Spring Boot 2.3.5
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ The approach taken here is to follow the model for JMS applications shown in the
[Spring Getting Started Guide for JMS](https://spring.io/guides/gs/messaging-jms/). That in turn
is based on using the [JmsTemplate Framework](https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#jms-jmstemplate)

A simple example program using Spring Boot and JMS interfaces can be found in the samples directory. The RUNME.sh program
compiles and executes it. The application.properties file in that tree may need modification for your environment.
Some simple example programs using Spring Boot and JMS interfaces can be found in the samples directory. The RUNME.sh program in
each subdirectory compiles and executes it. The application.properties files in that tree may need modification for your environment.

Essentially what gets configured from this package are a ConnectionFactory which Spring's JmsTemplate implementation
exploits to provide a simpler interface, and a MessageListener.
Expand Down Expand Up @@ -103,16 +103,17 @@ The queue manager name is given as

- `ibm.mq.queueManager`

For client connections to a queue manager, you must also set either
For client connections to a queue manager, you must also have either

- `ibm.mq.channel`
- `ibm.mq.connName`
or
- `ibm.mq.ccdtUrl`

If both the channel and connName are not supplied, and the CCDTURL is not supplied,
If both the channel and connName are empty, and the CCDTURL is not supplied,
then a local queue manager is assumed. The CCDTURL property is taken in preference to
the channel and connName.
the channel and connName. The channel and connName have non-blank defaults, so must be
explicitly set to empty strings if you do not wish them to be used.

Optionally you can provide a [client id](https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_latest/com.ibm.mq.ref.dev.doc/q112000_.html)
and [application name](https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_latest/com.ibm.mq.ref.dev.doc/q111810_.htm) if required.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.5
2.4.0
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ subprojects {
apply plugin: 'signing'

// Direct Dependencies - give versions here
ext.mqVersion = '9.2.0.0'
ext.springVersion = '5.2.10.RELEASE'
ext.springBootVersion = '2.3.5.RELEASE'
ext.mqVersion = '9.2.1.0'
ext.springVersion = '5.3.1'
ext.springBootVersion = '2.4.0'

ext.pooledJmsVersion = '1.2.0'
ext.pooledJmsVersion = '1.2.1'
ext.jUnitVersion = '4.13.1'

// The groupid for the compiled jars when uploaded
Expand Down
4 changes: 2 additions & 2 deletions samples/RUNME.sh → samples/s1/RUNME.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ echo "CLEAR QLOCAL(DEV.QUEUE.1)" | runmqsc -e QM1 >/dev/null 2>&1
######

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

./gradlew -p samples bootRun
./gradlew -p samples/s1 bootRun
4 changes: 2 additions & 2 deletions samples/build.gradle → samples/s1/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ apply plugin: 'org.springframework.boot'
// this repository without needing it released via maven
repositories {
flatDir() {
dirs '../mq-jms-spring-boot-starter'
dirs '../../mq-jms-spring-boot-starter'
}
mavenLocal()
mavenCentral()
}

dependencies {
compile("com.ibm.mq:mq-jms-spring-boot-starter:2.3.5")
compile("com.ibm.mq:mq-jms-spring-boot-starter:2.4.0")
}
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions samples/s2/RUNME.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.
#
# You may need to modify the application.properties file to get it to
# connect to your queue manager.

###### 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
######

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

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

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


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

// 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 {
compile("com.ibm.mq:mq-jms-spring-boot-starter:2.4.0")
}
16 changes: 16 additions & 0 deletions samples/s2/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/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("========================================");
}
}
10 changes: 10 additions & 0 deletions samples/s2/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

ibm.mq.queueManager=QM1
ibm.mq.channel=SYSTEM.DEF.SVRCONN
ibm.mq.connName=localhost(1414)

# 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

0 comments on commit 3a5e1b0

Please sign in to comment.