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

Using STOMP for testing Red Hat Message Servers (Part 1 - HornetQ)

August 13, 2014
Jason Marley

Share:

    On my latest engagement we were asked to setup and configure JBoss Fuse Service Works, which can either be configured with HornetQ (out of box) or ActiveMQ message servers. At the moment ActiveMQ requires the Karaf container and we couldn't convince ourselves it was right approach for this client.

    Anyhow, for Part 1, I wanted to focus on HornetQ and how easy it is to test your message server with STOMP (in part 2, I plan similar fun with ActiveMQ). I stumbled upon STOMP while looking for a HornetQ client for python and was intrigued with it's simplicity. Did I mention this protocol is supported my activeMQ as well...cool. I mean, with telnet and a few commands you're in business, subscribing/producing/consuming messages, which is perfect for testing. Using telnet is a nice approach, but trying to script something repeatable can get messy, so I decided it best to stick with the python library. There are slew of STOMP clients available and in various languages.

    Configure JBoss EAP HornetQ Server for STOMP via CLI - I'm not going to go through setting up hornetq from scratch, but rather show the configurations needed from STOMP to be leveraged.

    Add socket-binding group

    /socket-binding-group=standard-sockets/socket-binding=messaging-stomp:add(port=61613)

    Add STOMP Acceptor

    /subsystem=messaging/hornetq-server=default/remote-acceptor=stomp-acceptor:add(socket-binding=messaging-stomp)
    Add parameters: protocol, ttl and port
    /subsystem=messaging/hornetq-server=default/remote-acceptor=stomp-acceptor/param=protocol:add(value=stomp)
    /subsystem=messaging/hornetq-server=default/remote-acceptor=stomp-acceptor/param=connection-ttl:add(value=30000)
    /subsystem=messaging/hornetq-server=default/remote-acceptor=stomp-acceptor/param=port:add(value=61613)
    • Verify STOMP protocol
    # cat standalone/log/server.log | grep STOMP
    
    12:20:09,315 INFO  [org.hornetq.core.server] (MSC service thread 1-3) HQ221020: Started Netty Acceptor version 3.6.6.Final-redhat-1-fd3c6b7 0.0.0.0:61613 for STOMP protocol
    

    Configure STOMP client

    Download STOMP server client

    git clone git@github.com:jasonrbriggs/stomp.py.git

    add to python libraries

    cd /../stomp.py
    sudo python2.7 setup.py install

    Producer script

    import stomp
    import time
    
    # add server event listeners
    class HornetqListener(object):
        def on_connecting(self, host_and_port):
            print('on_connecting %s %s' % host_and_port)
        def on_error(self, headers, message):
            print('received an error %s' % (headers, message))
        def on_message(self, headers, body):
            print('on_message %s %s' % (headers, body))
        def on_heartbeat(self):
            print('on_heartbeat')
        def on_send(self, frame):
            print('on_send %s %s %s' % (frame.cmd, frame.headers, frame.body))
        def on_connected(self, headers, body):
            print('on_connected %s %s' % (headers, body))
        def on_disconnected(self):
            print('on_disconnected')
        def on_heartbeat_timeout(self):
            print('on_heartbeat_timeout')
        def on_before_message(self, headers, body):
            print('on_before_message %s %s' % (headers, body))
            return (headers, body)
    
    # params
    dest='jms.topic.spin'
    server=<hornetq-server-ip>
    port=61613
    
    # optional, based on hornetq config
    user=<message-queue-username>
    passwd=<message-queue-password>
    
    # make STOMP server connection
    conn = stomp.Connection(host_and_ports=[(server, port)], prefer_localhost=False,keepalive=True,vhost='irs.example.com')
    
    # instantiate listener
    conn.set_listener('',HornetqListener())
    
    conn.start()
    
    conn.connect(username=user,passcode=passwd,wait=True)
    
    # subscribe to queue
    conn.subscribe(destination=dest,id=1)
    
    # send messages with timestamp
    for x in range(5):
    # send message to queue
    conn.send(body='the current time is:  ' + str(time.strftime('%X')) , destination=dest,persistent='true')
    
    time.sleep(4)
    time.sleep(4)
    
    conn.disconnect()

    Subscriber script

    import stomp
    import time
    
    # add listeners for server events
    class HornetqListener(object):
        def on_connecting(self, host_and_port):
            print('on_connecting %s %s' % host_and_port)
        def on_error(self, headers, message):
            print('received an error %s' % (headers, message))
        def on_message(self, headers, body):
            print('on_message %s %s' % (headers, body))
        def on_heartbeat(self):
            print('on_heartbeat')
        def on_send(self, frame):
            print('on_send %s %s %s' % (frame.cmd, frame.headers, frame.body))
        def on_connected(self, headers, body):
            print('on_connected %s %s' % (headers, body))
        def on_disconnected(self):
            print('on_disconnected')
        def on_heartbeat_timeout(self):
            print('on_heartbeat_timeout')
        def on_before_message(self, headers, body):
            print('on_before_message %s %s' % (headers, body))
            return (headers, body)
    
    # params
    dest='jms.topic.spin'
    server=<hornetq-server-ip>
    port=61613
    
    # optional, based on hornetq config
    user=<message-queue-username>
    passwd=<message-queue-password>
    
    # make STOMP server connection
    conn = stomp.Connection(host_and_ports=[(server, port)], prefer_localhost=False,keepalive=True,vhost='irs.example.com', heartbeats=(20,20))
    
    # instantiate listener
    conn.set_listener('',HornetqListener())
    
    conn.start()
    
    conn.connect(username=user,passcode=passwd,wait=True)
    
    # subscribe to queue
    conn.subscribe(destination=dest,id=1)
    
    time.sleep(1200)
    conn.disconnect()

    execute scripts

    • test sending messages to queue
    python msg-send.py
    
    • test retrieving messages from queue
    python msg-subscribe.py
    

    gotchas

    There is one gotcha I experienced.  If you want to test failover with an active/passive server topology, the messages won't persist. The protocol is not officially supported and this feature hasn't been added to the STOMP protocol.

    Happy STOMPing!

    Recent Posts

    • Cloud bursting with confidential containers on OpenShift

    • Reach native speed with MacOS llama.cpp container inference

    • A deep dive into Apache Kafka's KRaft protocol

    • Staying ahead of artificial intelligence threats

    • Strengthen privacy and security with encrypted DNS in RHEL

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    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