Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

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

August 13, 2014
Jason Marley

    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

    • Red Hat Hardened Images: Top 5 benefits for software developers

    • How EvalHub manages two-layer Kubernetes control planes

    • Tekton joins the CNCF as an incubating project

    • Federated identity across the hybrid cloud using zero trust workload identity manager

    • Confidential virtual machine storage attack scenarios

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.