0

Let's define Spring Cloud functions like this:

  @Bean
  public Function<Message, Message> logfileEventFunction() {
    log.info("logfileEventFunction consumer defined");
    return message -> {
      log.info("logfileEventFunction called - {}", message);
      return message;
    };
  }

  @Bean
  public Consumer<Message> logfileEventConsumer() {
    log.info("Logfile consumer defined");
    return (logfileEvent) -> {
      log.info("Logfile consumer called - {}", logfileEvent);
    };
  }

with properties like this:

spring.cloud.stream.bindings.logfileEventFunction-out-0.group=logfileEventChannelQueue
spring.cloud.stream.bindings.logfileEventFunction-out-0.destination=logfileEventChannel-out-0
spring.cloud.stream.bindings.logfileEventConsumer-in-0.group=logfileEventChannelQueue
spring.cloud.stream.bindings.logfileEventConsumer-in-0.destination=logfileEventChannel-out-0

Besides defined logfileEventChannelQueue, Spring automatically create anonymous queue called logfileEventFunction-in-0. I'm adding also dependency spring-cloud-function-web to expose functions as an endpoint.

Expected behavior is that Function sends its output via queue to Consumer.

Everything works, when I'm putting message into anonymous queue, which is input for Function. Then Function resend this message to another queue which is bind to Customer.

The problem is that binding Function to output queue doesn't work, when called via REST endpoint. Function is called, but message is not passed to the output queue. Should it? I want to create REST endpoint which blindly outputs everything into queue.

Marx
  • 804
  • 10
  • 23

1 Answers1

0

I believe you're looking for StreamBridge. It was specifically designed for cases like yours. IN fact the provided example I believe exactly describes your case.

Let me know if that's not the case

Oleg Zhurakousky
  • 5,820
  • 16
  • 17
  • I've already implemented it with StreamBridge and it works. The question is about inconsistency - I expect that when I use endpoint from spring-cloud-function-web it will work with spring cloud stream bindings, which currently doesn't. Maybe it's a bug? – Marx Oct 17 '21 at 12:55
  • There is no inconsistency. One side (output) is is bound to the destination via s-c-stream binder; The other side (input) is exposed as REST endpoint by a completely different framework (e.g., Spring MVC). The StreamBridge "bridges" them together. – Oleg Zhurakousky Oct 18 '21 at 06:56
  • while I understand why it is like it is, I don't agree it's consistent. If a function is dumb, no matter how it's called, when it's output is bound to something, it should always use this binding and output a message using this binding. – Marx Oct 19 '21 at 09:33
  • Agree 100% if both sides are bindings (and that is what we have with binders, but they are not. One side (output) is bound using _spring-cloud-stream binder_ - binding. Another side (input) exposes function as REST endpoint outside of any knowledge of spring-cloud-stream framework. – Oleg Zhurakousky Oct 19 '21 at 15:41