About
A Spring Boot Starter module for automatic RabbitMQ client generation from interfaces.
Usage
Import the project as a dependency:
<dependency>
<groupId>org.bakeneko</groupId>
<artifactId>spring-boot-starter-rabbitmq-rpc</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>
Enable RPC client generation by annotating one of your Spring configuration classes with @EnableRabbitRPC
, for example:
@SpringBootApplication
@EnableRabbitRPC
public class MyAwesomeApp { ... }
Specify a org.springframework.amqp.support.converter.SmartMessageConverter
bean - fof JSON conversion org.springframework.amqp.support.converter.Jackson2JsonMessageConverter
is a common choice:
@Configuration
public class MyConfig {
@Bean
public MessageConverter converter() {
return new Jackson2JsonMessageConverter();
}
}
Create one or more interfaces annotated with @RabbitClient
:
@RabbitClient(
exchange="default exchange (if any)",
routingKey="default routing key (if any)",
messagePostProcessor="default message post processor bean name, if any"
)
public interface SomeClient {
@RabbitSender(
exchange="exchange overriding the default one (if necessary)"
routingKey="routing key overriding the default ont (if necessary)"
messagePostProcessor="message post processor bean name, to override the default one (if necessary)"
)
SomeResponseType someRequest(SomeRequestType request);
}
Methods in @RabbitClient
interfaces can optionally be marked with the @RabbitSender
annotation, to override the default metadata specified in @RabbitClient
.
Methods must have exactly 1 argument, or alternatively mark all parameters as @Payload
, @Header
or @Headers
.
If there is only one argument, it is considered to be @Payload
by default, no need to mark it explicitly.
There can only be one (mandatory) @Payload
argument and one (optional) @Headers
argument. The number of @Header
arguments is not restricted, you can have as many as you like.
After the initial setup the implementations can be @Autowired
by type into other beans:
@Service
public class SomeService {
@Autowired
private SomeClient autoGeneratedClient;
...
}