SpringCloudStream配置Rabbitmq的延迟队列配置

前言

使用springCloudStream实现Rabbitmq的延迟队列主要在配置如何配置。

  • Rabbitmq需要安装延迟队列插件
  • 参考:安装延迟插件

配置文件

spring:
  application:
    name: delayed-message
  cloud:
    stream:
      default-binder: rabbit
      binders:
        rabbit:
          type: rabbit
          environment:
            spring.rabbitmq.host: 127.0.0.1
            spring.rabbitmq.port: 5672
            spring.rabbitmq.username: guest
            spring.rabbitmq.password: guest
            spring.rabbitmq.virtual-host: cc
      bindings:
        faultDelayMessage-in-0:
          destination: fault-delayed-message
          group: fault-delayed-message
          consumer:
            autoStartup: true
            concurrency: 10
        faultDelayMessage-out-0:
          destination: fault-delayed-message
          group: fault-delayed-message
      rabbit:
        bindings:
          faultDelayMessage-in-0:
            consumer:
              delayed-exchange: true
              binding-routing-key: fault_message
              queue-name-group-only: true
              exchange-type: direct
          faultDelayMessage-out-0:
            producer:
              routing-key-expression: '''fault_message'''
              delayed-exchange: true
              exchange-type: direct
              queue-name-group-only: true

生产者

streamBridge.send("faultDelayMessage-out-0", ttt);

消费者

@Component("faultDelayMessage")
public class FaultDelayMessage implements Consumer<Message<byte[]>> {
    @Override
    public void accept(Message<byte[]> s) {
        System.out.println(System.currentTimeMillis() + " sss: " + s);
    }
}

你可能感兴趣的:(rabbitmq,java,rabbitmq,spring,cloud)