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

Asynchronous communication between microservices using AMQP and Vert.x

August 30, 2018
Faisal Masood
Related topics:
JavaMicroservices
Related products:
Streams for Apache Kafka

    Microservices are the go-to architecture in most new, modern software solutions. They are (mostly) designed to do one thing, and they must talk to each other to accomplish a business use-case. All communication between the microservices is via network calls; this pattern avoids tight coupling between services and provides better separation between them.

    There are basically two styles of communication: synchronous and asynchronous. These two styles applied properly are the foundation for request-reply and event-driven patterns. In the case of the request-reply pattern, a client initiates a request and typically waits synchronously for the reply. However, there are cases where the client could decide not to wait and register a callback with the other party, which is an example of the request-reply pattern in an asynchronous fashion.

    In this article, I am showcasing the approach of asynchronous request-reply by having two services communicate with each other over Advanced Message Queuing Protocol (AMQP). AMQP is an open standard for passing business messages between applications or organizations. Although this article focuses on the request-reply pattern, the same code can be used to develop additional scenarios like event sourcing. Communicating using an asynchronous model can be very beneficial for implementing the aggregator pattern.

    I will be using Apache QPid Proton (or Red Hat AMQ Interconnect) as the message router and the Vert.x AMQP bridge for communication between the two services.

    Solution components

    This demo has three components:

    1. frontend: This is a service written in Java and provides an HTTP endpoint to receive calls from clients. Upon receiving a request, the frontend service sends the call to the QPid router and registers a reply handler. The reply handler will be invoked by the Vert.x AMQP bridge when the response is available. The frontend folder in the codebase hosts this project.
    2. QPid router: The frontend process takes the call and posts a message to the QPid queue. Vert.x automatically takes care of adding a correlationId as the message property to identify a response to the original request.
    3. backend: The backend component listens for the message in the call from the QPid router, process it (e.g. doing a calculation or persisting in a database), and sends the response back to the QPid router. The QPid router will then notify the frontend component with the response. The backend folder in the codebase hosts this project.

    Message flow

    The basic flow of the messages across different components is as follows. The full details of this flow along with the relative headers can be found here.

    1. The frontend service will send a message to a QPid server and provides a reply handler. Vert.x automatically populates the required headers needed for request-reply communication.
    2. The receiving application, the backend service, consumes the message and sends a reply back to the QPid server. Vert.x populates the required headers needed for request-reply communication.
    3. The QPid server dispatches the reply message to the frontend service's reply handler. Vert.x bridge handles the invocation of the reply handler automatically.

    Clone this GitHub repo to get the example code.

    How to run the example: Quickstart

    You can use the Docker Compose file to run all three components of this example, by issuing the following command:

    docker-compose up

     

    How to run the example: The hard way

    This section summarizes how to run each component individually. You need the following software to run them on your laptop.

    1. Docker (for executing the Apache Qpid router)
    2. Open JDK 8 (to compile the frontend and the backend service components)
    3. Maven 3.2 (both services use Maven)
    4. Vegeta as an HTTP client (or you can use your favorite tool for this)

    Execution

    • Use the following command to start the local QPid router:
    docker run -it -p 5672:5672 ceposta/qdr
    • Compile and execute the frontend service:
    cd frontend 
    mvn clean install
    java -jar target/frontend-service-full.jar
    • Compile and execute the backend service:
    cd backend 
    mvn clean install
    java -jar target/backend-service-full.jar

     

    Testing

    Vegeta, an open source tool for HTTP load testing, can be used to post requests to the frontend component.

    echo "GET http://localhost:8080/" | ./vegeta attack -duration=60s -rate=50 | tee results.bin | ./vegeta report

     

    Verifying the number of messages and latency

    QPid provides an ultra-fast backbone as an asynchronous hub for communication between services. Once you finish testing your application, you can log into the QPid router's Docker container using its IMAGE ID and run qdstat to see various metrics.

    docker exec <container-name> qdstat -c
    docker exec <container-name> qdstat -l
    docker exec <container-name> qdstat -a
    
    

     

    Conclusion

    Apache QPid provides an ultra-fast backbone for communication between microservices. Since AMQP is a wire-level protocol, services written in other stacks (like .NET) can also use the same communication channel. Java developers can easily adapt to the AMQP-based asynchronous inter-services communication pattern using the Vert.x AMQP bridge.

    Last updated: January 17, 2022

    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.