0

I'm trying to use the "new" Streams plugin for RabbitMQ with my spring-cloud-stream project using "functional programming model".

I have set up my application.yaml like this:

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.send("testProducer-out-0", "testing..");

And my testconsumer looks like this:

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

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.

Does anyone have an idea of why?

bsgrd
  • 633
  • 1
  • 9
  • 26
  • I don't believe we support "stream" container type – Oleg Zhurakousky Sep 14 '22 at 13:43
  • Actually, I think I am wrong, as it was added recently, and have not been released. You should be using 4.0.0-SNAPSHOT - https://docs.spring.io/spring-cloud-stream/docs/4.0.0-SNAPSHOT/reference/html/spring-cloud-stream-binder-rabbit.html#rabbitmq-stream-consumer – Oleg Zhurakousky Sep 14 '22 at 13:48
  • Try fetching the latest the docker image; I have seen this error with older images. See https://github.com/spring-projects/spring-amqp/issues/1465#issuecomment-1240964228 – Gary Russell Sep 14 '22 at 14:18
  • @OlegZhurakousky I tried bumping the cloud version to 4.0.0-SNAPSHOT. If i'm using spring-cloud-stream and spring-cloud-stream-binder-rabbit, I get a NoClassDefFoundError for org/springframework/rabbit/stream/listener/StreamListenerContainer. If I use spring-cloud-starter-stream-rabbit I instead get ClassNotFoundException for RabbitStreamOperations – bsgrd Sep 15 '22 at 08:31
  • Can you please create a small project and push it to github somewhere so we can take a look? – Oleg Zhurakousky Sep 15 '22 at 13:33
  • @OlegZhurakousky sure https://github.com/bsgrd/demo I'm running rabbitmq in docker with image "rabbitmq:3.9-management" – bsgrd Sep 15 '22 at 14:55
  • @OlegZhurakousky any thoughts? – bsgrd Sep 19 '22 at 12:42
  • I asked @GaryRussell to take a look, stay tuned – Oleg Zhurakousky Sep 22 '22 at 09:17
  • You are using the wrong port; see my answer. – Gary Russell Sep 22 '22 at 12:26

1 Answers1

1

It looks like you are trying to connect over the AMQP port, not the stream port.

The stream port is 5552.

Are you mapping the streams port and enabling the plugin? https://blog.rabbitmq.com/posts/2021/07/rabbitmq-streams-first-application/

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks. It's connecting to the stream now. Is it possible to instruct it to read from offset 0? Currently it only reads new messages. – bsgrd Sep 24 '22 at 11:46
  • 1
    You shouldn't ask new, unrelated, questions in comments; it doesn't help people find questions/answers. Add a `ListenerConstainerCustomizer` bean which adds a `ConsumerCustomizer` to the container, which sets `OffsetSpecification.first()` on the consumer. If you need more help for how to do that, ask a new question. – Gary Russell Sep 26 '22 at 13:50