Crafting a REST Controller

Learn about Spring AMQP and how to create a Spring WebFlux REST controller.

Spring AMQP is dedicated to applying the “Spring way” to AMQP, a popular messaging protocol.

Adding AMQP dependency

The first step is to add Spring AMQP to our project’s build file:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
Adding Spring AMQP to the project

Defining the Spring WebFlux REST controller

Next, we need to create a Spring WebFlux REST controller class to respond to those POST calls:

@RestController //1
public class SpringAmqpItemController {
private static final Logger log =
LoggerFactory.getLogger(SpringAmqpItemController.class);
private final AmqpTemplate template; //2
public SpringAmqpItemController(AmqpTemplate template) {
this.template = template;
}
}
Configuring a reactive controller for AMQP messaging

Here’s a breakdown of the code above:

  1. In line 1, @RestController signals that this ...