7

Returning a Java Object List in RabbitMQ RPC

 3 years ago
source link: https://nixmash.com/java/returning-an-java-object-list-from-rabbitmq-rpc/
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.

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 we'll do is extend our Reservation system by including a "?" command line option to retrieve a list of Customers. Here's what that would look like.

rpclist0227a.png

At the Server

Let's first look at returning the Customer Object List from the RabbitMQ Server process. We're creating a new Queue to handle this process, but other than that the only changes are in the mapping of the List Object in Jackson at (1).

rpclist0227b.png

Handling the List Object on the Client

I just mentioned the Jackson ObjectMapper as being the focus on creating the Customer object list. We'll see it as the star on the Client Side as well (1). Apart from the mapping change we're using our new RPC_LIST_QUEUE and changing the definition of our response object to a BlockingQueue<List<Customer>>.

A sidebar on Jackson is that its use here is absolutely no different than when receiving an Object List from a REST Endpoint. You'll see that in my post Retrieving REST Data Object Lists with Jersey and Jackson. Nice!

rpclist0227c.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.

CategoriesJavaTagsBootique, Java, Json, RabbitMQ


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK