Code Monkey home page Code Monkey logo

spring-amqp-by-example's Introduction

Spring AMQP by Example

This project holds some code samples, snippets, tests and documentation for the Spring AMQP library.

Prerequisites

The tests in this project require a locally running Rabbit MQ broker. The easiest way to set it up is using a Docker container. Once you have Docker running on your machine, use the following commands to run Rabbit MQ in Docker:

rmq_container_id=$(docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq) && sleep 5 && docker exec $rmq_container_id rabbitmq-plugins enable rabbitmq_management

Collection of Examples

To make the examples easier to be run separately, each is written as a test within the src/test/java directory.

Example Description
Simple send and receive A very basic example to send an receive messages with RabbitTemplate
Spring Message Class Using the Spring Message abstraction to send and receive messages
Direct Exchange with Configuration and Listener Using a Direct Exchange with Spring @Configuration and a Message Listener
Direct Exchange with multiple Listeners Using a Direct Exchange with multiple Message Listeners
Direct Exchange with a annotated Listener Using a Direct Exchange with the @RabbitListener annotation
Fanout Exchange with Configuration and Listener Using a Fanout Exchange with Spring @Configuration and a Message Listener
Fanout Exchange with multiple Listeners Using a Fanout Exchange with multiple Message Listeners
Topic Exchange with multiple Listeners Using a Topic Exchange with multiple listeners
Publisher Confirm Using Publisher Confirms with multiple listeners

Some Remarks

Annnotation Based Listener

In order to use the @RabbitListener annotation, use the @EnableRabbit annotation in your @Configuration and make sure to define a SimpleRabbitListenerContainerFactory bean:

@Configuration
@EnableRabbit
public class RabbitConfiguration {

    @Bean
    public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);
        return factory;
    }

    @Bean
    public AnnotationBasedMessageListener annotationBasedMessageListener() {
        return new AnnotationBasedMessageListener();
    }

}



@Component
public class AnnotationBasedMessageListener {

    @RabbitListener(queues = "annotation-based-queue")
    public void onMessage(Message message) {
        // ...
    }

}

Further Resources

spring-amqp-by-example's People

Contributors

michaellihs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 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.