简体   繁体   English

Spring 云 Stream 与 RabbitMQ 流

[英]Spring Cloud Stream with RabbitMQ Streams

I'm trying to use the "new" Streams plugin for RabbitMQ with my spring-cloud-stream project using "functional programming model".我正在尝试使用“函数式编程模型”将 RabbitMQ 的“新”Streams 插件与我的 spring-cloud-stream 项目一起使用。

I have set up my application.yaml like this:我已经像这样设置了我的 application.yaml:

spring:
  rabbitmq:
    listener:
      type: stream
    stream:
      host: ${RABBIT_HOST:localhost}
      port: ${RABBIT_PORT:5672}
      username: guest
      password: guest
      name: demo
  cloud:
    function:
      definition: testConsumer
    stream:
      rabbit:
        bindings:
          testConsumer-in-0:
            consumer:
              containerType: stream
      bindings:
        testConsumer-in-0:
          group: demo
          destination: test
        testProducer-out-0:
          destination: test

I have a @PostConstruct method that uses StreamBridge like this:我有一个使用 StreamBridge 的 @PostConstruct 方法,如下所示:

streamBridge.send("testProducer-out-0", "testing..");

And my testconsumer looks like this:我的 testconsumer 看起来像这样:

@Bean
public Consumer<Flux<String>> testConsumer() {
    return flux -> flux.doOnEach(LOGGER::info);
}

But when I start my application, I get this exception:但是当我启动我的应用程序时,我得到了这个异常:

Caused by: com.rabbitmq.stream.StreamException: Could not get response in 10000 ms

And in the log of my RabbitMQ container I get this error:在我的 RabbitMQ 容器的日志中,我收到此错误:

2022-09-14 13:30:53.485574+00:00 [error] <0.32309.0> {bad_header,<<0,0,1,0,0,17,0,1>>}

If I set spring.cloud.stream.rabbit.bindings.testConsumer-in-0.consumer.containerType to direct, everything works fine.如果我将 spring.cloud.stream.rabbit.bindings.testConsumer-in-0.consumer.containerType 设置为direct,一切正常。

Does anyone have an idea of why?有谁知道为什么?

It looks like you are trying to connect over the AMQP port, not the stream port.看起来您正在尝试通过 AMQP 端口进行连接,而不是 stream 端口。

The stream port is 5552. stream 端口为 5552。

Are you mapping the streams port and enabling the plugin?您是否在映射流端口并启用插件? https://blog.rabbitmq.com/posts/2021/07/rabbitmq-streams-first-application/ https://blog.rabbitmq.com/posts/2021/07/rabbitmq-streams-first-application/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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