2016-09-17 65 views
0

我正在尝试使用RabbitMQ配置简单的Spring云流应用程序。我使用的代码大多取自spring-cloud-stream-samples。 我有一个入口点:Spring云流不会创建队列

@SpringBootApplication 
public class DemoApplication { 

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

,并从例如简单的消息生产者:

@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配置:

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

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

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

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

回答

2

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

在Rabbit MQ的情况下,我们为每个使用者组分别拥有不同的队列,并且我们无法事先知道所有组,如果您希望为预先知道的使用者组自动创建队列,则可以使用​​生产者的财产。这将确保消息持续到该组中的消费者启动为止。

查看详情这里:http://docs.spring.io/spring-cloud-stream/docs/Brooklyn.BUILD-SNAPSHOT/reference/htmlsingle/#_producer_properties

+0

是的,它的作品!谢谢。 – FVlad