Skip to main content

Getting Started

This quick start tutorial sets up a single node RabbitMQ and runs the sample reactive sender and consumer using Reactive Commons.

Requirements

You need Java JRE installed (Java 17 or later).

You also need to install RabbitMQ. Follow the instructions from the website

Start RabbitMQ

Start RabbitMQ on your local machine with all the defaults (e.g. AMQP port is 5672).

Containerized

You can run it with Docker or Podman

podman run -d -p 5672:5672 -p 15672:15672 --name rabbitmq rabbitmq:management-alpine

Spring Boot Application

The Spring Boot sample publishes and consumes messages with the DomainEventBus. This application illustrates how to configure Reactive Commons using RabbitMQ in a Spring Boot environment.

To build your own application using the Reactive Commons API, you need to include a dependency to Reactive Commons.

Current version

Maven metadata URL

Dependency

dependencies {
implementation "org.reactivecommons:async-commons-rabbit-starter:<version>"
}

Note: If you will use Cloud Events, you should include the Cloud Events dependency:

dependencies {
implementation 'io.cloudevents:cloudevents-json-jackson:4.0.1'
}

### Configuration properties

Also you need to include the name for your app in the `application.properties`, it is important because this value will
be used
to name the application queues inside RabbitMQ:

```properties
spring.application.name=MyAppName

Or in your application.yaml

spring:
application:
name: MyAppName

You can set the RabbitMQ connection properties through spring boot with the spring.rabbitmq.* properties

spring:
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
virtual-host: /

You can also set it in runtime for example from a secret, so you can create the RabbitProperties bean like:

org.reactivecommons.async.rabbit.config.RabbitProperties

@Configuration
public class MyRabbitMQConfig {

@Bean
@Primary
public RabbitProperties customRabbitProperties() {
RabbitProperties properties = new RabbitProperties();
properties.setHost("localhost");
properties.setPort(5672);
properties.setVirtualHost("/");
properties.setUsername("guest");
properties.setPassword("guest");
return properties;
}
}

Please refer to Configuration Properties Or with secrets Loading properties from a secret

The 5.x.x stable version of Reactive Commons has been merged with the deprecated -eda variant, this means that the async-commons-rabbit-starter artifact is now the only one to use.

This merge allows you to:

Multi Broker Instances of RabbitMQ or Multi Domain support

Enables to you the ability to listen events from different domains, send commands to different domains and make queries to different domains.

Cloud Events

Includes the Cloud Events specification.

If you want to use it, you should read the Creating a CloudEvent guide