Skip to content
This repository has been archived by the owner on Dec 17, 2019. It is now read-only.
/ spring-amqp-utils Public archive

Provides some utility-methods to simplify the use of Spring Amqp

License

Notifications You must be signed in to change notification settings

avides/spring-amqp-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring-amqp-utils

Maven Central Codacy Badge Coverage Status Build Status

Maven

<dependency>
    <groupId>com.avides.spring</groupId>
    <artifactId>spring-amqp-utils</artifactId>
    <version>1.0.1.RELEASE</version>
</dependency>

Available methods

AmpqUtils.buildDurableQueueWithDlx(String queueName, AmqpAdmin adminThatShouldDeclare)
AmpqUtils.buildDurableQueueWithDlx(String queueName, AmqpAdmin adminThatShouldDeclare, AmqpAdmin... furtherAdminsThatShouldDeclare)

AmpqUtils.buildDurableQueueWithDlxArguments(String queueName, AmqpAdmin adminThatShouldDeclare)
AmpqUtils.buildDurableQueueWithDlxArguments(String queueName, AmqpAdmin adminThatShouldDeclare, AmqpAdmin... furtherAdminsThatShouldDeclare)

AmpqUtils.buildDurableDlxQueueFor(Queue queue)
AmpqUtils.buildDurableDlxQueueFor(String queueName, AmqpAdmin adminThatShouldDeclare)
AmpqUtils.buildDurableDlxQueueFor(String queueName, AmqpAdmin adminThatShouldDeclare, AmqpAdmin... furtherAdminsThatShouldDeclare)

AmpqUtils.buildNonDurableQueueWithDlx(String queueName, AmqpAdmin adminThatShouldDeclare)
AmpqUtils.buildNonDurableQueueWithDlx(String queueName, AmqpAdmin adminThatShouldDeclare, AmqpAdmin... furtherAdminsThatShouldDeclare)

AmpqUtils.buildNonDurableQueueWithDlxArguments(String queueName, AmqpAdmin adminThatShouldDeclare)
AmpqUtils.buildNonDurableQueueWithDlxArguments(String queueName, AmqpAdmin adminThatShouldDeclare, AmqpAdmin... furtherAdminsThatShouldDeclare)

AmpqUtils.buildNonDurableDlxQueueFor(Queue queue)
AmpqUtils.buildNonDurableDlxQueueFor(String queueName, AmqpAdmin adminThatShouldDeclare)
AmpqUtils.buildNonDurableDlxQueueFor(String queueName, AmqpAdmin adminThatShouldDeclare, AmqpAdmin... furtherAdminsThatShouldDeclare)

AmqpUtils.buildDlxQueueFor(Queue queue)

Examples

Possibility 1
@Configuration
@EnableRabbit
public class RabbitConfiguration
{
    @Bean
    public Exchange exchange()
    {
        return new TopicExchange("exchange.name");
    }

    @Bean
    public Queue queue(AmqpAdmin amqpAdmin)
    {
        return AmqpUtils.buildDurableQueueWithDlx("queue.name", amqpAdmin);
    }
    
    @Bean
    public Binding binding(AmqpAdmin amqpAdmin)
    {
        return bind(queue(amqpAdmin)).to(exchange()).with("routing.key").noargs();
    }
}
Possibility 2

If you want to have access to the DLX-Queue-Bean

@Configuration
@EnableRabbit
public class RabbitConfiguration
{
    @Bean
    public Exchange exchange()
    {
        return new TopicExchange("exchange.name");
    }

    @Bean
    public Queue queue(AmqpAdmin amqpAdmin)
    {
        return AmqpUtils.buildDurableQueueWithDlxArguments("queue.name", amqpAdmin);
    }
    
    @Bean
    public Queue dlxQueue(AmqpAdmin amqpAdmin)
    {
        return AmqpUtils.buildDlxQueueFor(queue(amqpAdmin));
    }
    
    @Bean
    public Binding binding(AmqpAdmin amqpAdmin)
    {
        return bind(queue(amqpAdmin)).to(exchange()).with("routing.key").noargs();
    }
}
Possibility 3

The same as possibility 2, but referncing the Queue and the DLX-Queue via the queue-name

@Configuration
@EnableRabbit
public class RabbitConfiguration
{
    @Bean
    public Exchange exchange()
    {
        return new TopicExchange("exchange.name");
    }

    @Bean
    public Queue queue(AmqpAdmin amqpAdmin)
    {
        return AmqpUtils.buildDurableQueueWithDlxArguments("queue.name", amqpAdmin);
    }
    
    @Bean
    public Queue dlxQueue(AmqpAdmin amqpAdmin)
    {
        return AmqpUtils.buildDurableDlxQueueFor("queue.name", amqpAdmin);
    }
    
    @Bean
    public Binding binding(AmqpAdmin amqpAdmin)
    {
        return bind(queue(amqpAdmin)).to(exchange()).with("routing.key").noargs();
    }
}

In all given examples, it is also possible to give more than one RabbitAdmin/AmqpAdmin that should declare the queues. Also all examples can be made with non-durable-queues (use the AmqpUtils.buildNonDurable...-methods)