9

RabbitMQ RPC Java Demo With Bootique

 4 years ago
source link: https://nixmash.com/java/rabbitmq-rpc-java-demo-with-bootique/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

In this post I'm going to demonstrate using RabbitMQ RPC with the Bootique RabbitMQ Module. You can find RabbitMQ RPC examples elsewhere like in the RabbitMQ Java Examples on GitHub, but here we're going to enjoy the Bootique approach. All code in this post can be found in my NixMash Bootique RabbitMQ Demo repo on GitHub. Previous Bootique RabbitMQ-related posts are listed in the project's README.md file.

What is RabbitMQ RPC?

RPC stands for Remote Procedure Calls, or getting data back from a RabbitMQ Queue as well as send it. Up to this point we've had a one-way conversation with RabbitMQ Queues.

In our RPC Demo we're using the familiar Reservation Object and will be checking-in a guest. We have two task options:

  1. Send a String Message (the guest's name) to the RabbitMQ Server to receive a Customer object for additional local processing.
  2. Send a Reservation Object (the guest's name in {brackets}) to receive a quick summary message about the guest currently checking in.

Here is an example of both. First on the Client Side where we send a guest name of bob and receive a Customer object. Then we send a Reservation object and receive an quick summary message about our guest.

rpc0226a.png

Here is what the RabbitMQ Server receives, first a String followed by a Reservation object.

rpc0226b.png

On the Client

Below is our Client RPC method for the task of sending a Reservation object and receiving a Guest Summary message.

  1. We need to associate this RPC call with its return message so begin by creating a unique CorrelationId value.
  2. Create our Connection and Channel using Bootique then enter the CorrelationId in our AMQP Properties and the Queue Name for the returned data. Notice that the Queue Name is channel.queueDeclare().getQueue().
  3. Publish to the Queue along with our AMQP Properties and Reservation object.
  4. Setup our receipt from the Channel (channel.basicConsume() — notice the Queue Name) and handleDelivery(), looking for our unique CorrelationId.
rpc0226c.png

On the Server

On the Server end of the Queue we initialize our RabbitMQ Connection and Channel in Bootique, then

  1. Configure the Consumer for the RPC_MESSAGES_QUEUE Queue (listed at bottom of the method)
  2. Build our Reply Properties to include our unique CorrelationId.
  3. After performing our Reservation work we publish back to the Queue along with an Acknowledgment.
rpc0226d.png

Source Code Notes for this Post

Source code discussed in our Bootique RabbitMQ Series is found in my NixMash Bootique RabbitMQ Demo on GitHub.


Recommend

  • 53

    bootique - Bootique is a minimally opinionated platform for modern runnable Java apps.

  • 28
    • 微信 mp.weixin.qq.com 6 years ago
    • Cache

    使用 RabbitMQ 实现 RPC

  • 4
    • www.liwenzhou.com 4 years ago
    • Cache

    RabbitMQ Go语言客户端教程6——RPC

    本文翻译自RabbitMQ官网的Go语言客户端系列教程,共分为六篇,本文是第六篇——RPC。 这些教程涵盖了使用RabbitMQ创建消息传递应用程序的基础知识。 你需要安装RabbitMQ服务器才能完成这些教程,...

  • 13
    • nixmash.com 4 years ago
    • Cache

    A Bootique Command Demo Application

    A Bootique Command Demo Application Using Bootique Commands is a great way to put together tight little JARs to execute scheduled tasks with cron. We'll cover the basics of building a Bootique Command Application in this post.

  • 18

    Bearer Token Design in Bootique Shiro for REST Authentication My interest in using Bearer Authentication Tokens in Microservices began after reading

  • 39

    Single and Multiple File Uploads with Jersey and Bootique You'll find information on uploading single and multiple files with Jersey in many places, but there are a few details I'll emphasize in this post which may prove help...

  • 14

    A Bootique Logback Configuration File Example Probably every Bootique Application uses the Bootique Logback Module. All of my Bootique Apps do, yet I've always used a logback.xml file instead of a bootique.yml configuration. One of t...

  • 9

    Generic Type Injection Examples in Bootique and Guice Back when I was working in Spring I built a Jsoup Annotation-based parsing library which I blogged about here. It...

  • 8

    Returning a Java Object List in RabbitMQ RPC In this post we will build on returning Java Objects in RabbitMQ RPC by returning an Object List. What w...

  • 4
    • ijayer.github.io 2 years ago
    • Cache

    Rabbitmq | 06 - RPC

    这一节使用 RabbitMQ 构建 RPC 系统:包含一个客户端和一个可扩展的服务端,服务端是一个虚拟的 RPC Service,用来返回 Fibonacci 数 有关 RPC 的说明: 尽管 RPC 在计算过程中是一个非常常见的模型,它也经常受到批评。当程序员并不注意一个...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK