Skip to content

puskai/gs-rpc-rabbitmq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tags projects
messaging
rabbitmq
spring-amqp

This guide walks you through the process of setting up a RabbitMQ AMQP server and clinet for RPC calls.

What you’ll build

You’ll build an server application and a client application that calls the server using Spring AMQP’s RabbitTemplate.

Set up the project

build.gradle

link:initial/build.gradle[role=include]

Before you can build your messaging application, you need to set up the server that will handle receiving and sending messages.

RabbitMQ is an AMQP server. The server is freely available at http://www.rabbitmq.com/download.html. You can download it manually, or if you are using a Mac with homebrew:

brew install rabbitmq

Unpack the server and launch it with default settings.

rabbitmq-server

You should see something like this:

            RabbitMQ 3.1.3. Copyright (C) 2007-2013 VMware, Inc.
##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
##  ##
##########  Logs: /usr/local/var/log/rabbitmq/rabbit@localhost.log
######  ##        /usr/local/var/log/rabbitmq/rabbit@localhost-sasl.log
##########
            Starting broker... completed with 6 plugins.

Create a service

src/main/java/hello/CalculationService.java

link:complete/src/main/java/hello/CalculationService.java[role=include]

Create the service implementation

src/main/java/hello/CalculationServiceImpl.java

link:complete/src/main/java/hello/CalculationServiceImpl.java[role=include]

Create a RabbitMQ RPC server application

src/main/java/hello/ServerApplication.java

link:complete/src/main/java/hello/ServerApplication.java[role=include]

Create a RabbitMQ RPC client application

src/main/java/hello/ClientApplication.java

link:complete/src/main/java/hello/ClientApplication.java[role=include]

Create a RabbitMQ RPC client

src/main/java/hello/Client.java

link:complete/src/main/java/hello/Client.java[role=include]

Run the server application, than run the client application. You should see output like this:

91 + 96 =187.0
78 + 21 =99.0
60 * 59 =3540.0
91 + 49 =140.0
16 + 70 =86.0
34 * 91 =3094.0
32 + 97 =129.0

Summary

Congratulations! You’ve just developed a simple RPC server and client application with Spring and RabbitMQ. There’s more you can do with Spring and RabbitMQ than what is covered here, but this should provide a good start.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages