简体   繁体   中英

Setting Spring Cloud Rabbit + deadLetter

I have working configuration for Rebbit - send message from the main queue in the waiting (dead-letter) with TTL and throw it back from its expiration:

@Configuration
@AllArgsConstructor
public class RabbitConfig {

public static final String QUEUE_MESSAGES = "demo-messages-queue";
public static final String QUEUE_MESSAGES_DLQ = QUEUE_MESSAGES + ".dlq";
public static final String EXCHANGE_MESSAGES = "demo-messages-exchange";

@Bean
public DirectExchange exchange() {
    return new DirectExchange(EXCHANGE_MESSAGES);
}

@Bean
public Queue mainQueue() {
    return QueueBuilder
            .durable(QUEUE_MESSAGES)
            .withArgument("x-dead-letter-exchange", EXCHANGE_MESSAGES)
            .withArgument("x-dead-letter-routing-key", QUEUE_MESSAGES_DLQ)
            .build();
}

@Bean
public Queue deadLetterQueue() {
    return QueueBuilder
            .durable(QUEUE_MESSAGES_DLQ)
            .withArgument("x-dead-letter-exchange", EXCHANGE_MESSAGES)
            .withArgument("x-dead-letter-routing-key", QUEUE_MESSAGES)
            .withArgument("x-message-ttl", 30000)
            .build();
}

@Bean
public Binding mainBinding() {
    return BindingBuilder
            .bind(mainQueue())
            .to(exchange())
            .with(QUEUE_MESSAGES);
}

@Bean
public Binding deadLetterBinding() {
    return BindingBuilder
            .bind(deadLetterQueue())
            .to(exchange())
            .with(QUEUE_MESSAGES_DLQ);
 }
}

I can not repeat the same scheme for the Spring Cloud Stream in application.yml

spring:
  cloud:
    stream:
      binders:
        rabbitAll:
          type: rabbit
          environment:
            spring:
              rabbitmq:
                host: localhost
                port: 5672
                virtual-host: test
                username: guest
                password: guest
      rabbit:
        bindings:
          demo-messages-push-input:
            consumer:
              bindingRoutingKey: demo-messages-queue
              routingKeyExpression: '''demo-messages-queue'''
              bindQueue: true
              autoBindDlq: true
              dlqTtl: 30000
      bindings:
        demo-messages-push-input:
          destination: demo-messages-queue
          binder: rabbitAll
        demo-messages-push-output:
          destination: demo-messages-queue
          binder: rabbitAll

I would be grateful for the help and working example in application.yml

See the documentation .

Specifically dlqDeadLetterExchange and dlqDeadLetterRoutingKey .

You've already got dlqTtl .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM