Coder Social home page Coder Social logo

rabbit4lazy's Introduction

rabbit4lazy

The l̶a̶z̶i̶e̶s̶t̶ fastest way to set up RabbitMQ in your Spring Boot application

Install

You don't even need to manually add Spring AMQP. The library take care of everything for you.

Maven

<dependency>
    <groupId>com.github.pedrocomitto</groupId>
    <artifactId>rabbit4lazy</artifactId>
    <version>1.0.0</version>
</dependency> 

Gradle

implementation 'com.github.pedrocomitto:rabbit4lazy:1.0.0'

Usage

Configure

In addition to the RabbitMQ properties, just add spring.rabbitmq.bindings.<binding-name>.autoGenerate=true to your application.properties and it's done!

Example using "send-notification" as binding:

spring:
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest
    bindings: <------- rabbit4lazy binding
      send-notification: <----- example binding name
        autoGenerate: true <---- automatically generates an exchange, a queue and a DLQ

or

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.bindings.send-notification.autoGenerate=true

With the above properties, it will automatically generate:

send-notification.exchange
send-notification.queue
send-notification.queue.dlq

Produce

Now you can use a Spring Bean called "GenericProducer" to send data:

genericProducer.produce(String bindingName, Object message)

Example:

@Service
public class MyService {

    // GenericProducer bean
    private final GenericProducer genericProducer;
    
    // constructor injection
    public MyService(GenericProducer genericProducer) {
        this.genericProducer = genericProducer;
    }

    // method receiving an example object "Notification" and sending it to RabbitMQ
    public void myExampleMethod(final Notification notification) {
        genericProducer.produce("send-notification", notification);
    }
} 

The above example, will send a message to the "send-notification.exchange".

Other customizations

Alternatively, you can define your own exchange, queue and dlq names:

spring:
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest
    bindings: <------- rabbit4lazy binding
      send-notification: <----- example binding name
        exchangeName: send-sms.exchange
        queueName: send-sms.queue
        dlqName: send-sms.queue.dlq

or

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.bindings.send-notification.exchangeName=send-sms.exchange
spring.rabbitmq.bindings.send-notification.queueName=send-sms.queue
spring.rabbitmq.bindings.send-notification.dlqName=send-sms.queue.dlq

rabbit4lazy's People

Contributors

pedrocomitto avatar

Watchers

 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.