Giter VIP home page Giter VIP logo

spring-boot-spring-amqp-java8-lombok-sample's Introduction

Spring Boot + Spring AMQP + Java 8 Optional and Dates + Lombok Sample

Sample RabbitMQ producer and consumer application with minimum setup.

Project contains two submodules:

  • producer - with an example how to send message to RabbitMQ.
  • consumer - with an example how to retrieve message from RabbitMQ.

Both projects use Lombok to minimise the boilerplate.

Hints

  • in order to enable Jackson to (de)serialize java.util.Optional following dependency has to be added:
<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
  • in order to enable Jackson to (de)serialize Java 8 date formats following dependency has to be added:
<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
  • to keep objects containing data passed in a message immutable, they annotated with Lombok @Value. Since Lombok version 1.16.20, you need to explicitly instruct it to generate @ConstructorProperties by adding following line to lombok.config file:
lombok.anyConstructor.suppressConstructorProperties=false
  • by default Spring AMQP does not utilize Spring Boot configured Jackson ObjectMapper. To take the advantage of Jackson autoconfiguration you need to add following bean:
@Bean
MessageConverter messageConverter(ObjectMapper objectMapper) {
    return new Jackson2JsonMessageConverter(objectMapper);
}
  • to test reliably if message gets send and received, in integration tests you should use anonymous queues so that each listener in each concurrently running application context has its own queue and listeners do not hijack messages from each other causing tests to fail randomly. This is why it's a good idea to externalise properties like queue name, routing key, exchange to @ConfigurationProperties classes
  • integration testing of the listener should only cover if message gets received and if it's deserialized properly. Testing the logic should not be a part of an integration test
  • to write integration test for a listener following dependency has to be added:
<dependency>
    <groupId>org.springframework.amqp</groupId>
    <artifactId>spring-rabbit-test</artifactId>
    <version>${spring-amqp.version}</version>
    <scope>test</scope>
</dependency>

where spring-amqp.version is a property coming from Spring Boot parent project - you don't need to specify this version by yourself.

  • to take the advantage of spring-rabbit-test, @RabbitListenerTest(capture = true) needs to be added to test configuration setup. Check RabbitTestConfiguration
  • check BookListenerTest to see an example integration test.

spring-boot-spring-amqp-java8-lombok-sample's People

Contributors

maciejwalkowiak avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.