Tutorial
Take the coding challenge: Code, build, and deploy an IBM MQ app to AWS Cloud
Get hands-on with the code behind the messaging playground sample appDevelop, deploy, and debug a sample messaging application with IBM MQ and AWS Cloud. In this hands-on coding challenge, you configure message properties and message selection to route donations across multiple currencies.
To continue building your messaging skills, you expand on the messaging playground sample app deployed in the Build and deploy an IBM MQ app to AWS Cloud tutorial.
By getting hands-on with the code, you can develop, deploy, and debug a new feature in a messaging app, which gets you ready for the badge quiz to earn the IBM MQ Developer for AWS Essentials badge.
In this coding challenge, you learn how to:
- Set a message property on an IBM MQ message when you put it onto a queue.
- Read message properties when you get a message from a queue.
- Use a message selector to receive only the messages that match a property value.
- Run, debug, and rebuild a containerized messaging application on your own machine.
You choose how much to code. You can review a complete solution (Option 1), fix the bugs in a working implementation (Option 2), or write the solution yourself (Option 3).
Prerequisites
- Clone the mq-dev-patterns repository to your local machine.
- Complete the tutorial on the IBM MQ messaging playground sample app.
- Install Git.
- Install Podman on your local machine. For the setup steps, see Step 1.
- Install docker-compose. You do not need Docker Desktop or the Docker daemon. For the setup steps, see Step 1.
The coding challenge
You develop a university donations application for a fictional university research project that allows the academic team to accept donations in multiple currencies for its new global research program. Sponsors can visit the program website and make a contribution in a currency of their choice. In the initial version of the solution, 3 currencies are supported (USD, EUR, and GBP).
The proof of concept (PoC) solution is modeled within the messaging playground sample app platform that you previously deployed.
Your code performs the following tasks:
- Produces and consumes a message on a donation queue (
DEV.QUEUE.1). - Sets a message property (
currency) to represent the currency in which the donation is made. The message payload represents the value of the donation only. - Routes the funds to the bank accounts of the university, which allows researchers to optimize their processing and accounting functions.
You work with the message-session-manager.js JavaScript file. It uses the IBM MQ MQI API with Node.js to connect to and exchange messages with IBM MQ.
To ensure developers with a range of experience can complete the coding challenge, 3 options are available:
- Option 1: Just show me the code: The
message-session-manager-ModelAnswer.jsfile contains the full working code. You can review the code in this file to see how the challenge is solved. - Option 2: Get familiar with the code: The
message-session-manager-brokenModelAnswer.jsfile includes an implementation for the new feature, but contains bugs that you must fix to achieve the expected application behavior. - Option 3: Code the solution: The
message-session-manager.jsfile provides the starting point for you to develop your own solution to the challenge.
If you are new to coding, start with Option 1 or Option 2. If you are an experienced developer, you can start directly with Option 3.
Architecture of the client app
The proposed system architecture enables sponsors to donate funds to the university. Building the full end-to-end solution requires developing multiple microservices and presentation tiers. To simplify the implementation, this coding challenge focuses on the message and message property exchanged between the microservices. The tutorial uses the presentation layer from the showcase application to minimize coding effort. To visualize both the producer (donation) and consumer (funds received) messaging actions, the roles of both parties are presented on a single webpage.

The webpages for making and receiving donations are part of the presentation layer, which sends PUT or GET requests to the Message Session Manager (MSM). The Message Session Manager processes these requests by completing the MQ PUT and GET operation requests.
The entire messaging playground application is built on 3 layers (presentation layer, Message Session Manager, and Queue Manager), and each layer is deployed as an individual container.
The changes to the presentation layer are already implemented. Enable this new tab to integrate with your newly coded features after you develop them.
The code needed to deploy the architecture is in the mq-dev-patterns GitHub repository.
This repository also includes a wide range of samples for many APIs, frameworks, and programming languages that IBM MQ supports.
The only directory that you use for this coding challenge is ibm-messaging-mq-cloud-showcase-app. If you decide to code the solution yourself, you can find useful hints in the other projects.
The ibm-messaging-mq-cloud-showcase-app directory is structured as follows:

- The
frontenddirectory contains the code for the presentation layer. - The
backenddirectory contains the code for the Message Session Manager. Themsmssubdirectory contains themessage-session-manager.jssource files needed for this challenge. - The
.envfile contains environment variables and deployment parameters. - The
docker-compose.yamlfile is used bypodman composeto build the container images for the frontend and the Message Session Manager, and to run them together with the queue manager on your local machine. - The
cdkdirectory contains the AWS CDK stack that deploys the same 3 containers on AWS.
Run the playground app locally
For this coding challenge, prepare and run the messaging playground application locally. To streamline debugging and deployment, test the code changes on your local machine before you publish them to AWS.
In the mq-dev-patterns repository that you cloned to your local machine, open the ibm-messaging-mq-cloud-showcase-app subdirectory in your editor, and run all commands in this tutorial from that directory.
Step 1. Install and check the container tools
The containers are built and run with Podman and the podman compose command.
To use Docker instead of Podman, replace podman compose with docker compose in every command, and skip the rest of this step. The docker-compose.yaml file and the Dockerfiles are the same for both. On macOS where docker links to Podman, docker compose still uses Podman. To verify that you are connected to a Docker engine, run the docker version command.
On macOS, Podman runs inside a virtual machine, so you must also create and start a virtual machine. Install the tools with Homebrew and start the Podman machine:
brew install podman docker-compose
podman machine init # only the first time
podman machine start
The podman compose command is a thin wrapper that runs docker-compose as its compose provider. Check that podman compose uses docker-compose:
podman compose version
The output should include Executing external compose provider ".../docker-compose". The command is podman compose (with a space). It is not the same tool as podman-compose (with a hyphen), which is a separate Python project.
If podman compose picks a different provider, force docker-compose:
export PODMAN_COMPOSE_PROVIDER=$(which docker-compose)
Step 2. Set the passwords and turn on the coding challenge
The repository does not include an .env file. It includes a template file named .env.example. From the ibm-messaging-mq-cloud-showcase-app directory, create your .env file from the template:
cp .env.example .env
Set these variables in ibm-messaging-mq-cloud-showcase-app/.env:
- Set
APP_PASSWORDandADMIN_PASSWORDto the passwords you use for interacting (as a messaging user and as an administrator) on the queue manager. - Set
REACT_APP_IS_FOR_CODING_CHALLENGEtotrue. This setting switches the app from the ticket reseller screen to the university donations screen, both locally and on AWS.
For example, the .env file looks like the following image. Add your 2 passwords after APP_PASSWORD= and ADMIN_PASSWORD=:

The .env file contains passwords in plain text. Do not commit it, and use stronger passwords for anything that stays deployed.
Step 3. Choose the queue manager image
The mq service in docker-compose.yaml runs IBM MQ in a container. Pick the option that matches your machine.
Option A: Intel and AMD machines (Linux x86_64, Intel macOS)
Use the IBM MQ developer image from the IBM Container Registry. In docker-compose.yaml, the mq service should read:
mq:
image: "icr.io/ibm-messaging/mq:latest"
platform: linux/amd64
No further action is needed. Go to Step 4.
Option B: Apple Silicon (arm64) Macs
The IBM MQ image (icr.io/ibm-messaging/mq:latest) is linux/amd64 only. Podman on Apple Silicon runs it under emulation, thanks to the platform: linux/amd64 directive already set in docker-compose.yaml, so leave it as it is.
If you use Docker instead of Podman, the Docker engine must also be able to run linux/amd64 containers on Apple Silicon. If it cannot, use the native ARM64 option later in this step.
The backend image is built as linux/amd64 as well. With Podman, the platform: linux/amd64 line in docker-compose.yaml only sets the platform of the running container. It does not set the platform of the build, so backend/Dockerfile sets it on its FROM lines (the BUILD_PLATFORM build argument, which defaults to linux/amd64). This is needed because the ibmmq npm package has no linux-arm64 prebuilt binary. Without it, podman compose build runs the build as arm64, and npm ci stops with node-gyp: Could not find any Python installation to use. Building the backend under emulation is slower, so allow several minutes for the first build.
Optional: Run natively on ARM64
If you prefer to run natively and not under emulation, follow the guide for IBM MQ container images on Apple Silicon to build an ARM64 queue manager image from the MQ Container GitHub repository. The backend also needs an ARM64 IBM MQ C client library and a compiler toolchain, because the ibmmq package only downloads the library automatically on Linux x64 and Windows.
In
docker-compose.yaml, replace themqimage with the ARM64 image you built, and delete theplatform: linux/amd64line from both themqandbeservices:image: "localhost/ibm-mqadvanced-server-dev:10.0.0.0-arm64"In
backend/Dockerfile, install a compiler toolchain in the builder stage, replacing thenpm ciline:RUN apt-get update && apt-get install -y python3 make g++ --no-install-recommends && rm -rf /var/lib/apt/lists/* && npm ci --omit=devIn the runtime stage, after
COPY --from=builder ..., copy the MQ C client library from the ARM64 image:COPY --from=localhost/ibm-mqadvanced-server-dev:10.0.0.0-arm64 /opt/mqm/lib64 /opt/mqm/lib64 COPY --from=localhost/ibm-mqadvanced-server-dev:10.0.0.0-arm64 /opt/mqm/lib /opt/mqm/lib COPY --from=localhost/ibm-mqadvanced-server-dev:10.0.0.0-arm64 /opt/mqm/msg /opt/mqm/msg COPY --from=localhost/ibm-mqadvanced-server-dev:10.0.0.0-arm64 /opt/mqm/gskit9 /opt/mqm/gskit9Build the backend for ARM64 and start:
podman compose -f docker-compose.yaml down -v podman compose -f docker-compose.yaml build --build-arg BUILD_PLATFORM=linux/arm64 be podman compose -f docker-compose.yaml up -d
Step 4. Check that the donations screen is enabled
To change from the ticket reseller and management system that you deployed in the Build and deploy an IBM MQ app to AWS Cloud tutorial to this university donations system, you already set REACT_APP_IS_FOR_CODING_CHALLENGE=true in the .env file. You do not need to edit anything else.
The frontend is a Vite application, and Vite reads this value when the image is built, not when the container starts. The flag flows from the .env file into the build like this:
docker-compose.yamlpasses it to thefeservice as a build argument (REACT_APP_IS_FOR_CODING_CHALLENGE, defaultfalse).frontend/Dockerfilereceives it with anARGline beforeRUN npm run build.frontend/AWS-MQ-showcase/vite.config.tswrites the value into the frontend bundle.
This requires a version of the mq-dev-patterns repository that includes these three pieces. Check them:
grep -n "REACT_APP_IS_FOR_CODING_CHALLENGE" docker-compose.yaml frontend/Dockerfile frontend/AWS-MQ-showcase/vite.config.ts
You should see a match in each of the three files. If any file has no match, the flag is not wired into your copy of the repository. In that case, the app still starts but it shows the ticket reseller screen instead of the donations screen.
Because the value is part of the image, any time you change the flag you must rebuild the frontend image (podman compose -f docker-compose.yaml build --no-cache fe).
Your messaging playground application is now configured for this challenge and ready to be tested on your local machine using Podman containers.
Step 5. Build and start the containers
To build the containers (the presentation layer and Message Session Manager) and prepare the queue manager image for the messaging playground application, run the following command in your terminal:
podman compose -f docker-compose.yaml build
After the containers are built, start the messaging playground application by running the following command:
podman compose -f docker-compose.yaml up
Add -d to the end of the command to run the containers in the background. The initial start of the queue manager takes approximately 1 minute.
When the application is running, the log displays lines similar to the following example:
mq-1 | ... AMQ8003I: IBM MQ queue manager 'QM1' started using V10.0.0.0.
mq-1 | ... Started web server
node-be | > node server.js
Check that the 3 containers are running:
podman ps --format '{{.Names}} {{.Status}}'
Open the messaging playground application by navigating to: http://localhost:3000
The MQ web console is also reachable locally at: https://localhost:9443/ibmmq/console (accept the self-signed certificate warning and sign in as admin with your ADMIN_PASSWORD).
Learn more about the console in the Set up and use the IBM MQ Console tutorial.
In the messaging playground app, you can add multiple producers and consumers. For each producer application, you can specify the donation amount and currency. The donation is modeled as a message produced by the producer and consumed by a consumer. Consumers receive donations only in the assigned currency.
After selecting the amount and currency, the producer sends a donation by clicking Send cash.

For each university consumer account, you can select the currency to filter donations.

To stop the application, press Ctrl+C (or, if you used -d, run podman compose -f docker-compose.yaml down).
Code the university donations application
The default message-session-manager.js file contains the implementation for Option 3. To use a different version, copy one of the other files over it. From the ibm-messaging-mq-cloud-showcase-app directory:
For Option 1 (Just show me the code):
cp backend/AWS-showcase-backend/msms/message-session-manager-ModelAnswer.js \ backend/AWS-showcase-backend/msms/message-session-manager.jsFor Option 2 (Get familiar with the code):
cp backend/AWS-showcase-backend/msms/message-session-manager-brokenModelAnswer.js \ backend/AWS-showcase-backend/msms/message-session-manager.js
The backend code is copied into the container image during the build. After you change message-session-manager.js, follow the steps in Apply your changes.
The messaging playground application supports the following functions to handle the university donations application:
- Sets the donation currency as a message property on PUT requests.
- Sets a filter on messages based on the selected currency of the university bank account.
- Retrieves and returns the message payload (donation amount) and the currency message property to the frontend.
Consuming applications must read both the payload and the currency property to establish the correct donation amount and its currency.
An IBM MQ message consists of 3 parts: a descriptor, message properties, and the payload:
- Message descriptor (MQMD): Contains control information for message routing and management. For example, it contains a unique message ID and timestamp.
- Message properties: Stored by the application to associate metadata with the message. In this application, a message property stores the currency of a donation. This allows messages to be routed to the appropriate bank account processing stage without inspecting the payload.
- Payload: Contains the core application content, which in this case is the donation amount.
Solve the coding challenge using Option 1: Just show me the code
Review the code in the message-session-manager-ModelAnswer.js file. The challenge is to identify the lines of code that set message properties and filter by properties.
This version contains the complete working solution for the coding challenge. The methods to PUT, GET, and filter messages are implemented correctly. If you need assistance with Option 2 or Option 3, review this code to see how the challenge is solved.
Solve the coding challenge using Option 2: Get familiar with the code
Work with the message-session-manager-brokenModelAnswer.js file. This version contains the implementation, but includes bugs that you must fix.
Focus your debugging on the following methods:
performPutWithPropertiesgetSingleMessageWithProperties
In this version, a producer can send a donation, but the currency property that enables message filtering is misconfigured. Because of this configuration issue, consumers do not receive messages. In addition, the currency value returned from the getSingleMessageWithProperties method is incorrect.
Although the GET and PUT functions contain bugs, you can run the messaging playground application to observe the behavior.
Solve the coding challenge using Option 3: Code the solution
The methods to PUT, GET, and filter messages are not implemented. For this option, work with the message-session-manager.js file.
For examples of setting and reading message properties in Node.js, see the mq-mqi-nodejs repository.
For an example of selecting (filtering) messages from a queue, see the IBM MQ documentation on message selectors.
Implement the following functions to solve this challenge: performPutWithProperties, getSingleMessageWithProperties, and performOpen.
performPutWithProperties method
The performPutWithProperties method puts messages (donations) with properties onto a queue. This function is triggered when a producer sends a donation by clicking Send cash in the frontend component.
This method receives 2 parameters:
message: The donation amount.quantity: The number of donations per transaction (always1in this scenario).
Within this method, use the following class properties:
this.currency: The donation currency is stored in this class property and is not passed as a parameter.this[_HCONNKEY]andthis[_HOBJKEY]: Connection values for the queue and queue manager required to perform the PUT operation.
The message data to PUT into the queue must be a JSON object with the following schema:
msgObject = {
'Message' : message,
'Count' : quantity,
'Sent' : '' + new Date()
};
This method must return a Promise. Set the currency as a property of the message when putting it onto the queue.
getSingleMessageWithProperties method
The getSingleMessageWithProperties method gets a single message and its properties from a queue and returns them to the frontend.
This function does not take parameters.
Within this method, use the following class properties:
this[_HCONNKEY]andthis[_HOBJKEY]: Connection values for the queue and queue manager required to perform the GET operation.
This method must return a Promise. If the GET request succeeds, resolve msgObject with a JSON object that has the following schema:
msgObject = {
msgObject : contentOfTheMessageObtained,
properties : {
currency : currencyFromTheMessageProperty
}
}
If an error occurs, call resolve(null).
performOpen method
The performOpen method creates a connection with a queue. In this method, specify the currency selector to filter messages for GET requests.
Debug the university donations application
The debugger helps you observe the behavior of the Message Session Manager. Debug output is written to the backend container log.
To start the debugger, replace the last line of backend/Dockerfile (CMD ["npm", "start"]) with CMD ["npm", "run", "debug"].
By default, the debugger attaches to all JavaScript files in the Message Session Manager directory that contain the debug_info variable pattern require('debug')('mqapp-[*]:info');.
To activate the debugger on a single file, set the debug field in backend/AWS-showcase-backend/package.json to the corresponding debug_info variable of that file. For example, to activate debugging for worker.js (which uses let debug_info = require('debug')('mqapp-mqclient:info');), set debug in package.json to DEBUG=mqapp-mqclient node server.js.
To follow the debug output, run: podman compose -f docker-compose.yaml logs -f be
Apply your changes
To apply your changes, rebuild and redeploy the container images:
Stop running containers from the
ibm-messaging-mq-cloud-showcase-appdirectory:podman compose -f docker-compose.yaml downRebuild the container images:
podman compose -f docker-compose.yaml buildRestart the containers:
podman compose -f docker-compose.yaml up
After testing your solution locally, deploy the messaging playground application to AWS by following the steps in the Build and deploy an IBM MQ app to AWS Cloud tutorial.
If you run into problems, see the IBM MQ on AWS developer cheat sheet for troubleshooting.
Summary
In this coding challenge, you gained hands-on experience with the code behind the messaging playground sample application and learned how applications put and get properties into and from an MQ message and how message selection occurs.
The flexibility, scalability, and openness of IBM MQ allows you, with minor changes in message-session-manager.js, to configure how messages are exchanged between your applications without changing system business logic.