-
Notifications
You must be signed in to change notification settings - Fork 181
Added the java samples #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Hannah-Jones997
wants to merge
1
commit into
master
Choose a base branch
from
hannah-add-mq-java
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,143 @@ | ||
| # IBM Java-MQ Samples | ||
|
|
||
| This project provides a set of base Java samples for interacting with IBM MQ using the IBM MQ classes for Java (non-JMS). These include basic examples for put/get, publish/subscribe, and request/response messaging patterns. | ||
|
|
||
| ## Samples Included | ||
|
|
||
| Each sample is located under: | ||
|
|
||
| ``` | ||
| src/main/java/com/ibm/mq/samples/java/ | ||
| ``` | ||
|
|
||
| - `BasicPut.java` – Puts a message onto a queue | ||
| - `BasicGet.java` – Gets a message from a queue | ||
| - `BasicPub.java` – Publishes a message to a queue (persisted publish) | ||
| - `BasicSub.java` – Subscribes and receives messages from a queue | ||
| - `BasicRequest.java` – Sends a message with a dynamic reply-to queue | ||
| - `BasicResponse.java` – Responds to requests received from a queue | ||
| - `BasicProducer.java` – Produces a message to a queue (used by request wrappers) | ||
| - `BasicConsumer.java` – Consumes a message from a queue (used by request/response logic) | ||
| - `MQDetails.java` – POJO to hold MQ connection configuration | ||
| - `SampleEnvSetter.java` – Utility to parse `env.json` and load MQ endpoint configurations | ||
| - Wrapper Classes (used internally for iterating over endpoints): | ||
| - `BasicPutWrapper.java` | ||
| - `BasicGetWrapper.java` | ||
| - `BasicPubWrapper.java` | ||
| - `BasicSubWrapper.java` | ||
| - `BasicRequestWrapper.java` | ||
| - `BasicResponseWrapper.java` | ||
|
|
||
| > **Note**: Wrapper classes are utility helpers and should not be run directly. | ||
| ## Prerequisites | ||
|
|
||
| - Java 8 or higher | ||
| - Apache Maven | ||
| - IBM MQ installed and running (locally or remotely) | ||
|
|
||
| ## Project Setup | ||
|
|
||
| This is a standard Maven project. All dependencies and build instructions are managed through `pom.xml`. | ||
|
|
||
| ### Building the Project | ||
|
|
||
| To build the project and download dependencies: | ||
|
|
||
| ```bash | ||
| mvn clean package | ||
| ``` | ||
|
|
||
| ## Running the Samples | ||
|
|
||
| Ensure that your environment configuration file (`env.json`) is properly set up. | ||
|
|
||
| ## Using a CCDT File | ||
|
|
||
| Instead of manually specifying connection parameters in `env.json`, you can use a **Client Channel Definition Table (CCDT)** JSON file to define connection configurations. This is useful when connecting to IBM MQ instances in cloud or enterprise environments. | ||
|
|
||
| Set the environment variable `MQCCDTURL` to point to the CCDT file: | ||
|
|
||
| ```bash | ||
| export MQCCDTURL=file:/absolute/path/to/ccdt.json | ||
| ``` | ||
|
|
||
| > **Note (Windows):** Use `set` instead of `export`: | ||
| > | ||
| > ```cmd | ||
| > set MQCCDTURL=file:C:\path\to\ccdt.json | ||
| > ``` | ||
| The sample will detect `MQCCDTURL` and automatically use it for connection settings. When `MQCCDTURL` is set and starts with `file://`, the program prioritizes CCDT-based configuration and skips `host`, `channel`, and `port` in `env.json`. | ||
| Make sure your CCDT file defines the appropriate connection information such as **channel name**, **queue manager**, and **connection name list**. | ||
| ## Run Instructions | ||
| All samples should be run using the following format: | ||
| ```bash | ||
| mvn exec:java \ | ||
| -Dexec.mainClass="com.ibm.mq.samples.java.<ClassName>" \ | ||
| -Dexec.args="-Dcom.ibm.mq.cfg.jmqiDisableAsyncThreads=true" \ | ||
| -Dexec.jvmArgs="-DENV_FILE=./env.json" | ||
| ``` | ||
| ### Put | ||
| The number at the end of args is the number of messages you want to put to the queue, to change the number of message you put, simply change the number at the end of the argument. | ||
|
|
||
| ```bash | ||
| mvn exec:java \ | ||
| -Dexec.mainClass="com.ibm.mq.samples.java.BasicPut" \ | ||
| -Dexec.args="-Dcom.ibm.mq.cfg.jmqiDisableAsyncThreads=true 5" \ | ||
| -Dexec.jvmArgs="-DENV_FILE=./env.json" | ||
| ``` | ||
| ### Get | ||
| The number at the end of args is the number of messages you want to get from the queue, to change the number of message you get, simply change the number at the end of the argument. | ||
|
|
||
| ```bash | ||
| mvn exec:java \ | ||
| -Dexec.mainClass="com.ibm.mq.samples.java.BasicGet" \ | ||
| -Dexec.args="-Dcom.ibm.mq.cfg.jmqiDisableAsyncThreads=true 5" \ | ||
| -Dexec.jvmArgs="-DENV_FILE=./env.json" | ||
| ``` | ||
|
|
||
| ### Publish/Subscribe | ||
|
|
||
| **First terminal (subscriber):** | ||
|
|
||
| ```bash | ||
| mvn exec:java \ | ||
| -Dexec.mainClass="com.ibm.mq.samples.java.BasicSub" \ | ||
| -Dexec.args="-Dcom.ibm.mq.cfg.jmqiDisableAsyncThreads=true" \ | ||
| -Dexec.jvmArgs="-DENV_FILE=./env.json" | ||
| ``` | ||
|
|
||
| **Second terminal (publisher):** | ||
|
|
||
| ```bash | ||
| mvn exec:java \ | ||
| -Dexec.mainClass="com.ibm.mq.samples.java.BasicPub" \ | ||
| -Dexec.args="-Dcom.ibm.mq.cfg.jmqiDisableAsyncThreads=true" \ | ||
| -Dexec.jvmArgs="-DENV_FILE=./env.json" | ||
| ``` | ||
|
|
||
| ### Request/Response | ||
|
|
||
| **First terminal (response):** | ||
|
|
||
| ```bash | ||
| mvn exec:java \ | ||
| -Dexec.mainClass="com.ibm.mq.samples.java.BasicResponse" \ | ||
| -Dexec.args="-Dcom.ibm.mq.cfg.jmqiDisableAsyncThreads=true" \ | ||
| -Dexec.jvmArgs="-DENV_FILE=./env.json" | ||
| ``` | ||
|
|
||
| **Second terminal (request):** | ||
|
|
||
| ```bash | ||
| mvn exec:java \ | ||
| -Dexec.mainClass="com.ibm.mq.samples.java.BasicRequest" \ | ||
| -Dexec.args="-Dcom.ibm.mq.cfg.jmqiDisableAsyncThreads=true" \ | ||
| -Dexec.jvmArgs="-DENV_FILE=./env.json" | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| - The environment can be configured using either `env.json` or a CCDT file via the `MQCCDTURL` environment variable. | ||
| - Samples like `BasicResponse` and `BasicSub` are long-running and wait for messages until terminated or a timeout occurs. | ||
| - **Wrapper classes** are designed to iterate over all endpoints in `env.json`, but are not meant to be executed directly from the command line. | ||
| - Make sure all relevant queues and topics are pre-created in your IBM MQ queue manager. | ||
This file contains hidden or 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,48 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <groupId>com.ibm.mq.samples</groupId> | ||
| <artifactId>base-mq-java</artifactId> | ||
| <name>mq-dev-patterns</name> | ||
| <version>1.0.0</version> | ||
| <url>https://github.com/ibm-messaging/mq-dev-patterns/</url> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <artifactId>maven-shade-plugin</artifactId> | ||
| <version>3.2.4</version> | ||
| <executions> | ||
| <execution> | ||
| <phase>package</phase> | ||
| <goals> | ||
| <goal>shade</goal> | ||
| </goals> | ||
| <configuration> | ||
| <transformers> | ||
| <transformer> | ||
| <mainClass>com.ibm.mq.samples.jms.BasicSampleDriver</mainClass> | ||
| </transformer> | ||
| </transformers> | ||
| <filters> | ||
| <filter> | ||
| <artifact>*:*</artifact> | ||
| <excludes> | ||
| <exclude>META-INF/*.SF</exclude> | ||
| <exclude>META-INF/*.DSA</exclude> | ||
| <exclude>META-INF/*.RSA</exclude> | ||
| </excludes> | ||
| </filter> | ||
| </filters> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <properties> | ||
| <maven.compiler.target>1.8</maven.compiler.target> | ||
| <maven.test.skip>true</maven.test.skip> | ||
| <maven.compiler.source>1.8</maven.compiler.source> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| </properties> | ||
| </project> |
This file contains hidden or 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,48 @@ | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In stead of duplicating this file, is it possible to use the |
||
| "MQ_ENDPOINTS": [{ | ||
| "HOST": "127.0.0.1", | ||
| "PORT": "1415", | ||
| "CHANNEL": "DEV.APP.SVRCONN", | ||
| "QMGR": "*QM1TLS", | ||
| "APP_USER": "app", | ||
| "APP_PASSWORD": "passw0rd", | ||
| "QUEUE_NAME": "DEV.QUEUE.1", | ||
| "BACKOUT_QUEUE": "DEV.QUEUE.2", | ||
| "MODEL_QUEUE_NAME": "DEV.APP.MODEL.QUEUE", | ||
| "DYNAMIC_QUEUE_PREFIX": "APP.REPLIES.*", | ||
| "TOPIC_NAME": "dev/", | ||
| "CIPHER": "TLS_RSA_WITH_AES_128_CBC_SHA256", | ||
| "CIPHER_SUITE": "TLS_RSA_WITH_AES_128_CBC_SHA256", | ||
| "KEY_REPOSITORY": "../keys/clientkey" | ||
| },{ | ||
| "HOST": "127.0.0.1", | ||
| "PORT": "1414", | ||
| "CHANNEL": "DEV.APP.SVRCONN", | ||
| "QMGR": "*QMGroupA", | ||
| "APP_USER": "app", | ||
| "APP_PASSWORD": "passw0rd", | ||
| "QUEUE_NAME": "DEV.QUEUE.1", | ||
| "BACKOUT_QUEUE": "DEV.QUEUE.2", | ||
| "MODEL_QUEUE_NAME": "DEV.APP.MODEL.QUEUE", | ||
| "DYNAMIC_QUEUE_PREFIX": "APP.REPLIES.*", | ||
| "TOPIC_NAME": "dev/" | ||
| },{ | ||
| "HOST": "127.0.0.1", | ||
| "PORT": "1416", | ||
| "CHANNEL": "DEV.APP.SVRCONN", | ||
| "QMGR": "*QMGroupB", | ||
| "APP_USER": "app", | ||
| "APP_PASSWORD": "passw0rd", | ||
| "QUEUE_NAME": "DEV.QUEUE.1", | ||
| "BACKOUT_QUEUE": "DEV.QUEUE.2", | ||
| "MODEL_QUEUE_NAME": "DEV.APP.MODEL.QUEUE", | ||
| "DYNAMIC_QUEUE_PREFIX": "APP.REPLIES.*", | ||
| "TOPIC_NAME": "dev/" | ||
| }], | ||
| "JWT_ISSUER" : { | ||
| "JWT_TOKEN_ENDPOINT":"https://<KEYCLOAK_URL>/realms/master/protocol/openid-connect/token", | ||
| "JWT_TOKEN_USERNAME":"app", | ||
| "JWT_TOKEN_PWD":"passw0rd", | ||
| "JWT_TOKEN_CLIENTID":"admin-cli" | ||
| } | ||
| } | ||
This file contains hidden or 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,88 @@ | ||
| <!-- | ||
| (c) Copyright IBM Corporation 2025 | ||
| Licensed to the Apache Software Foundation (ASF) under one or more | ||
| contributor license agreements. See the NOTICE file distributed with | ||
| this work for additional information regarding copyright ownership. | ||
| The ASF licenses this file to You 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. | ||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 | ||
| http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>com.ibm.mq.samples</groupId> | ||
| <artifactId>base-mq-java</artifactId> | ||
| <version>1.0.0</version> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <name>mq-dev-patterns</name> | ||
| <url>https://github.com/ibm-messaging/mq-dev-patterns/</url> | ||
|
|
||
| <properties> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <maven.compiler.source>1.8</maven.compiler.source> | ||
| <maven.compiler.target>1.8</maven.compiler.target> | ||
| <maven.test.skip>true</maven.test.skip> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <!-- MQ Classes for Java (Base Java MQ API) --> | ||
| <dependency> | ||
| <groupId>com.ibm.mq</groupId> | ||
| <artifactId>com.ibm.mq.allclient</artifactId> | ||
| <version>9.4.3.0</version> | ||
| </dependency> | ||
|
|
||
| <!-- JSON library --> | ||
| <dependency> | ||
| <groupId>org.json</groupId> | ||
| <artifactId>json</artifactId> | ||
| <version>20240303</version> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-shade-plugin</artifactId> | ||
| <version>3.2.4</version> | ||
| <executions> | ||
| <execution> | ||
| <phase>package</phase> | ||
| <goals> | ||
| <goal>shade</goal> | ||
| </goals> | ||
| <configuration> | ||
| <transformers> | ||
| <transformer | ||
| implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
| <mainClass>com.ibm.mq.samples.jms.BasicSampleDriver</mainClass> | ||
| </transformer> | ||
| </transformers> | ||
| <filters> | ||
| <filter> | ||
| <artifact>*:*</artifact> | ||
| <excludes> | ||
| <exclude>META-INF/*.SF</exclude> | ||
| <exclude>META-INF/*.DSA</exclude> | ||
| <exclude>META-INF/*.RSA</exclude> | ||
| </excludes> | ||
| </filter> | ||
| </filters> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an explanation as to why we have to set
com.ibm.mq.cfg.jmqiDisableAsyncThreads