Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

4 steps to set up the MQTT secure client for Red Hat AMQ 7.4 on OpenShift

 

September 25, 2019
Chandra Shekhar Pandey
Related topics:
JavaKubernetes
Related products:
AMQ ClientsStreams for Apache KafkaRed Hat OpenShift

Share:

    In this article, we show how to set up Red Hat AMQ 7.4 on Red Hat OpenShift. Also, we show how to connect the external Message Queuing Telemetry Transport (MQTT) secure client to the AMQ 7.4 platform. MQTT is a Java-based client that uses the Eclipse Paho library and can publish and consume messages from Red Hat AMQ 7.4 Broker on OpenShift using secure transport. These commands and code have been verified with OpenShift 3.11.

     

    Follow the steps below to perform this activity.

    Step 1: Create a secret and a service account

    In a new OpenShift project, create a secret and a service account with the view role:

    [cpandey@cpandey AMQ74_CERTIFICATE]$ oc new-project amq-demo
    [cpandey@cpandey AMQ74_CERTIFICATE]$ echo '{"kind": "ServiceAccount", "apiVersion": "v1", "metadata": {"name": "amq-service-account"}}' | oc create -f -
    [cpandey@cpandey AMQ74_CERTIFICATE]$ oc policy add-role-to-user view system:serviceaccount:amq-demo:amq-service-account
    [cpandey@cpandey AMQ74_CERTIFICATE]$ keytool -genkey -alias broker -keyalg RSA -keystore broker.ks
    [cpandey@cpandey AMQ74_CERTIFICATE]$ keytool -export -alias broker -keystore broker.ks -file broker_cert
    [cpandey@cpandey AMQ74_CERTIFICATE]$ keytool -genkey -alias client -keyalg RSA -keystore client.ks
    [cpandey@cpandey AMQ74_CERTIFICATE]$ keytool -import -alias broker -keystore client.ts -file broker_cert
    [cpandey@cpandey AMQ74_CERTIFICATE]$ oc create secret generic amq-app-secret --from-file=broker.ks
    [cpandey@cpandey AMQ74_CERTIFICATE]$ oc secrets add sa/amq-service-account secret/amq-app-secret
    

    Note: All of these steps are mentioned in the official Red Hat Documentation, with details.

    Step 2: Deploy Red Hat AMQ 7.4 Broker

    Deploy Red Hat AMQ 7.4 broker using the OpenShift web console:

    1. Broker setup is easy with the OpenShift GUI. In the amq-demo project, browse the catalog and search for the template Red Hat A-MQ 7.4 (Ephemeral with SSL). The following six figures describe the information that you need to fill in for Broker setup. Once the configuration is complete, click the Create button:
    Browse Catalog
    1. Browse Catalog
    Select Template
    2. Select Template
    Configuration-1
    3. Configuration-1
    Configuration-2
    4. Configuration-2
    Configuration-3
    5. Configuration-3
    Final Step
    6. Final Step
    1. Run the following commands to check for services and pods. After a successful setup, you should have these available:
    [cpandey@cpandey AMQ74_CERTIFICATE]$ oc get service|grep ssl
    brokertest-amq-amqp-ssl ClusterIP 172.30.4.207 5671/TCP 2m
    brokertest-amq-mqtt-ssl ClusterIP 172.30.145.232 8883/TCP 2m
    brokertest-amq-stomp-ssl ClusterIP 172.30.20.224 61612/TCP 2m
    brokertest-amq-tcp-ssl ClusterIP 172.30.160.172 61617/TCP 2m
    [cpandey@cpandey AMQ74_CERTIFICATE]$
    
    [cpandey@cpandey AMQ74_CERTIFICATE]$ oc get pod
    NAME READY STATUS RESTARTS AGE
    brokertest-amq-1-z2xjq 1/1 Running 0 3m
    [cpandey@cpandey AMQ74_CERTIFICATE]$
    1. Now, create a route in the current project (amq-demo) for the MQTT service brokertest-amq-mqtt-ssl so that external clients can access Red Hat AMQ 7.4 in OpenShift. Set this route's termination type to passthrough so that the encrypted traffic goes to Red Hat AMQ 7.4 broker and TLS termination is not done at the route, specifically:
    [cpandey@cpandey AMQ74_CERTIFICATE]$ oc create route passthrough --service brokertest-amq-mqtt-ssl route.route.openshift.io/brokertest-amq-mqtt-ssl created
    1. Now, if we check routes available in the current project (amq-demo):
    [cpandey@cpandey AMQ74_CERTIFICATE]$ oc get route
    NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
    brokertest-amq-mqtt-ssl brokertest-amq-mqtt-ssl-amq-demo.192.168.42.111.nip.io brokertest-amq-mqtt-ssl passthrough None
    console console-amq-demo.192.168.42.111.nip.io brokertest-amq-jolokia passthrough None
    [cpandey@cpandey AMQ74_CERTIFICATE]$
    

    Step 3: Set up the Java MQTT client

    Now, set up the Java MQTT client external to your OpenShift environment. Once the route is configured, we just have to provide that URL in our client. Check out my personal GitHub code for examples:

    • For the MQTT publisher client, check out MqttPublishSample.java.
    • For the MQTT subscriber client, check out MqttSubscribeSample.java .
    • To execute these clients, use ThreadFactory.java.

    Note that we are using the client truststore client.ts, which we generated in Step 1.

    Step 4: Monitor topic statistics

    Now that you're set up, you can monitor your topic statistics:

    [cpandey@cpandey AMQ74_CERTIFICATE]$ oc get pods
    NAME READY STATUS RESTARTS AGE
    brokertest-amq-1-z2xjq 1/1 Running 0 14m
    [cpandey@cpandey AMQ74_CERTIFICATE]$ oc rsh brokertest-amq-1-z2xjq
    sh-4.2$ cd /opt/amq/bin
    sh-4.2$ ./artemis queue stat
    OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
    |NAME |ADDRESS |CONSUMER_COUNT |MESSAGE_COUNT |MESSAGES_ADDED |DELIVERING_COUNT |MESSAGES_ACKED |
    |DLQ |DLQ |0 |0 |0 |0 |0 |
    |ExpiryQueue |ExpiryQueue |0 |0 |0 |0 |0 |
    |activemq.management.b75e216e-902d-4393-8961-4a45dc54e4b6|activemq.management.b75e216e-902d-4393-8961-4a45dc54e4b6|1 |0 |0 |0 |0 |
    |paho3709101254858.MQTT_paho|MQTT_paho |0 |0 |9 |0 |9 |
    |queue1 |queue1 |0 |0 |0 |0 |0 |
    sh-4.2$

    Wrapping up

    That's it. I hope this article helps you to quickly set up Red Hat AMQ 7.4 on OpenShift, plus the external secure client using the MQTT protocol. You can also check out this developer blog for setting up Red Hat AMQ 6.3 on OpenShift with the Camel-based Openwire Client using SSL.

    Last updated: January 22, 2024

    Recent Posts

    • What's New in OpenShift GitOps 1.18

    • Beyond a single cluster with OpenShift Service Mesh 3

    • Kubernetes MCP server: AI-powered cluster management

    • Unlocking the power of OpenShift Service Mesh 3

    • Run DialoGPT-small on OpenShift AI for internal model testing

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue