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 the STOMP Protocol with Apache ActiveMQ Artemis Broker

June 14, 2018
Chandra Shekhar Pandey
Related topics:
Python
Related products:
Streams for Apache Kafka

    In this article, we will use a Python-based messaging client to connect and subscribe to a topic with a durable subscription in the Apache ActiveMQ Artemis broker. We will use the text-based STOMP protocol to connect and subscribe to the broker. STOMP clients can communicate with any STOMP message broker to provide messaging interoperability among many languages, platforms, and brokers.

    If you need to brush up on the difference between persistence and durability in messaging, check Mary Cochran's article on developers.redhat.com/blog.

    A similar process can be used with Red Hat AMQ 7. The broker in Red Hat AMQ 7 is based on the Apache ActiveMQ Artemis project. See the overview on developers.redhat.com for more information.

    Setting Up the Project

    In the following example, we are using one client, both to publish and subscribe to a topic. You can find the code at my personal GitHub repo. We have two receiver_queue.py and receiver_topic.py Python messaging clients. While receiver_queue.py is a Python client based on the STOMP protocol for point-to-point (queue) connection to the broker, receiver_topic.py is a Python client based on the STOMP protocol for durable subscription against a topic to the broker.

    Here is the code:

    import time
    import sys
    
    import stomp
    
    class MyListener(stomp.ConnectionListener):
     def on_error(self, headers, message):
     print('received an error "%s"' % message)
     def on_message(self, headers, message):
     print('received a message "%s"' % message)
    hosts = [('localhost', 61616)]
    
    conn = stomp.Connection(host_and_ports=hosts)
    conn.set_listener('', MyListener())
    conn.start()
    conn.connect('admin', 'admin', wait=True,headers = {'client-id': 'clientname'} )
    conn.subscribe(destination='A.B.C.D', id=1, ack='auto',headers = {'subscription-type': 'MULTICAST','durable-subscription-name':'someValue'})
    
    conn.send(body=' '.join(sys.argv[1:]), destination='A.B.C.D')
    
    time.sleep(2)
    conn.disconnect()
    

    The following are tasks performed by this code:

    • To receive messages from the messaging system, we need to set up a listener on a connection, and then later subscribe to the destination.
    • We are establishing a connection to the broker available locally on port 61616. The first parameter to a Connection is host_and_ports. This contains an IP address and the port where the message broker is listening for STOMP connections.
    • The start method creates a socket connection to the broker.
    • Then we use the connect method with credentials to access the broker and we use the headers client-id to ensure that the subscription that is created is durable.
    • Once a connection is established to the broker with subscribe method, we are subscribing to destination A.B.C.D using acknowledgment mode auto. Also, we must provide the headers subscription-type as MULTICAST and durable-subscription-name as some text value.
    • To create a durable subscription, the client-id header must be set on the CONNECT frame and the durable-subscription-name must be set on the SUBSCRIBE frame. The combination of these two headers will form the identity of the durable subscription.
    • After a connection is established to the broker, we can use the send method to send/produce messages to the destination A.B.C.D. Here the first argument is to accept the text/string value from the command line, and the second argument is destination name or topic name.

    How to Execute the Python Client

    • Make sure the  Apache ActiveMQ Artemis broker is configured to support the STOMP protocol. By default, port 61616 is configured to support almost all messaging protocols.
    <acceptor name="artemis">tcp://0.0.0.0:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300</acceptor>
    
    • To run the client using the STOMP protocol, we first need the stomp module so that components of the STOMP API, such as connect, start,  send, subscribe, and disconnect, are available. So install the stomp module first.
    pip install stomp.py
    
    • Once the stomp module is installed, we can easily run the client in the following way:
    [cpandey@vm254-231 python_stomp_example]$ python receiver_topic.py "Hello World"
    received a message "Hello World"
    [cpandey@vm254-231 python_stomp_example]$
    
    • We can check the results using the following commands from the Apache ActiveMQ Artemis broker:
    [cpandey@vm254-231 bin]$ ./artemis address show
    
    A.B.C.D
    DLQ
    
    [cpandey@vm254-231 bin]$ ./artemis queue stat --user admin --password admin --url tcp://localhost:61616
    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 |
    |clientname.someValue |A.B.C.D |0 |0 |1 |0 |1 |
    [cpandey@vm254-231 bin]$
    

    Note: A.B.C.D is the Address created and the durable subscription is created as queue clientname.someValue.

    • If we read the network dumps using Wireshark, the following is the complete stream:
    STOMP
    accept-version:1.1
    client-id:clientname
    login:admin
    passcode:admin
    
    .CONNECTED
    version:1.1
    session:4c98c896
    server:ActiveMQ-Artemis/2.4.0.amq-711002-redhat-1 ActiveMQ Artemis Messaging Engine
    
    .
    SUBSCRIBE
    ack:auto
    destination:A.B.C.D
    durable-subscription-name:someValue
    id:1
    subscription-type:MULTICAST
    
    .SEND
    content-length:4
    destination:A.B.C.D
    
    abcd.MESSAGE
    subscription:1
    content-length:4
    message-id:30
    destination:A.B.C.D
    expires:0
    redelivered:false
    priority:4
    persistent:false
    timestamp:1528858440363
    
    abcd.
    DISCONNECT
    receipt:6a8bc1fd-0c8b-4e13-871f-fbc9c8c4df9d
    
    .RECEIPT
    receipt-id:6a8bc1fd-0c8b-4e13-871f-fbc9c8c4df9d
    

    That's it. I hope this helps you to have a basic understanding of using the STOMP protocol with the Apache ActiveMQ Artemis or Red Hat AMQ 7.

    Last updated: September 3, 2019

    Recent Posts

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    • Fun in the RUN instruction: Why container builds with distroless images can surprise you

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

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

    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.