tags | projects | |||
---|---|---|---|---|
|
|
This guide walks you through the process of setting up a RabbitMQ AMQP server and clinet for RPC calls.
You’ll build an server application and a client application that calls the server using Spring AMQP’s RabbitTemplate
.
+ - RabbitMQ server (installation instructions below)
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.
src/main/java/hello/CalculationService.java
link:complete/src/main/java/hello/CalculationService.java[role=include]
src/main/java/hello/CalculationServiceImpl.java
link:complete/src/main/java/hello/CalculationServiceImpl.java[role=include]
src/main/java/hello/ServerApplication.java
link:complete/src/main/java/hello/ServerApplication.java[role=include]
src/main/java/hello/ClientApplication.java
link:complete/src/main/java/hello/ClientApplication.java[role=include]
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
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.