Spring Cloud Stream 不创建队列 [英] Spring Cloud Stream does not create a queue

查看:30
本文介绍了Spring Cloud Stream 不创建队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 RabbitMQ 配置一个简单的 Spring Cloud Stream 应用程序.我使用的代码主要取自 spring-cloud-stream-samples.我有一个入口点:

I'm trying to configure a simple Spring Cloud Stream application with RabbitMQ. The code I use is mostly taken from spring-cloud-stream-samples. I have an entry point:

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

和示例中的简单消息生产者:

and a simple messages producer from the example:

@EnableBinding(Source.class)
public class SourceModuleDefinition {

    private String format = "yyyy-MM-dd HH:mm:ss";

    @Bean
    @InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "${fixedDelay}", maxMessagesPerPoll = "1"))
    public MessageSource<String> timerMessageSource() {
        return () -> new GenericMessage<>(new SimpleDateFormat(this.format).format(new Date()));
    }

}

另外,这里是 application.yml 配置:

Additionally, here is application.yml configuration:

fixedDelay: 5000
spring:
  cloud:
    stream:
      bindings:
        output:
          destination: test

当我运行该示例时,它会连接到 Rabbit 并创建一个名为 test 的交换.但我的问题是,它不会自动创建队列和绑定.我可以看到 Rabbit 中的流量,但是我所有的消息都消失了.虽然我需要它们留在某个队列中,除非它们被消费者读取.

When I run the example, it connects to Rabbit and creates an exchange called test. But my problem is, it doesn't create a queue and binding automatically. I can see traffic going in Rabbit, but all my messages are then gone. While I need them to stay in some queue unless they are read by consumer.

也许我误解了一些东西,但从我阅读的所有主题来看,Spring Cloud Stream 似乎应该自动创建一个队列和一个绑定.如果没有,我如何配置它以便我的消息被持久化?

Maybe I misunderstand something, but from all the topics I read, it seems like Spring Cloud Stream should create a queue and a binding automatically. If not, how do I configure it so my messages are persisted?

我使用的是 Spring Cloud Brixton.SR5 和 Spring Boot 1.4.0.RELEASE.

I'm using Spring Cloud Brixton.SR5 and Spring Boot 1.4.0.RELEASE.

推荐答案

只要您启动消费者应用程序,就会创建一个队列.

A queue would be created as soon as you start a consumer application.

在Rabbit MQ的情况下,我们为每个消费者组都有单独的队列,并且我们不能事先知道所有的组,如果你想为预先知道的消费者组自动创建队列,你可以使用<生产者的 code>requiredGroups 属性.这将确保消息被持久化,直到来自该组的消费者被启动.

In the case of Rabbit MQ, where we have separate queues for each consumer group and we cannot know all groups beforehand, if you want to have the queues created automatically for consumer groups that are known in advance, you can use the requiredGroups property of the producers. This will ensure that messages are persisted until a consumer from that group is started.

在此处查看详细信息:http://docs.spring.io/spring-cloud-stream/docs/Brooklyn.BUILD-SNAPSHOT/reference/htmlsingle/#_producer_properties

这篇关于Spring Cloud Stream 不创建队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆