英文:
Spring Cloud Stream Function support does not work
问题
我正在尝试使用Spring Cloud Stream与如此主题中描述的函数一起使用。 但它不起作用。
我的函数:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
@Bean
public Consumer<String> consumer() {
return s -> System.out.println(s);
}
}
然后我通过使用@Output
注解创建的生产者向consumer-in-0
通道推送消息:
public interface Source {
@Output("source")
MessageChannel producer();
}
source.producer().send(MessageBuilder.withPayload("Hello").build());
我的YAML通道配置:
spring:
cloud:
function:
definition: consumer
stream:
bindings:
source:
destination: consumer-in-0
如果我通过@Input
配置使用消费者 - 一切正常。 同样在rabbitmq管理器中,我可以看到生产者正在工作并发送消息,但消费者未消耗它们。 请有人帮帮我。
附注:我还在使用Spring WebFlux。
英文:
I trying to use Spring Cloud Stream with functions as that described in this topic. But it does not work.
My function:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
@Bean
public Consumer<String> consumer() {
return s -> System.out.println(s);
}
}
And I push message. to the consumer-in-0
channel via producer that made with @Output
annotation:
pulic interface Source {
@Output("source")
MessageChannel producer();
}
source.producer().send(MessageBuilder.withPayload("Hello").build());
My yaml channels configuration:
spring:
cloud:
function:
definition: consumer
stream:
bindings:
source:
destination: consumer-in-0
If I use consumer via @Input
configuration - everything ok.
Also in rabbitmq manager I see that producer is working and sending messages, but consumer does not consuming them.
Help me please somebody.
P.S. I also use Spring WebFlux
答案1
得分: 4
以下是您要的翻译内容:
您不能在同一个应用程序中混合使用EnableBinding
和功能模型。如果您在同一个应用程序中既有生产者又有消费者,您可能希望使用Supplier
将您的生产者转换为功能模型。例如,
@Bean
public Supplier<String> supplier() {
return () -> MessageBuilder.withPayload("Hello").build();
}
然后,
spring:
cloud:
function:
definition: supplier;consumer
stream:
bindings:
supplier-out-0:
destination: consumer-in-0
英文:
You cannot mix EnableBinding
and functional model in the same application. If you are putting both producer and consumer in the same application, you might want to convert your producer using a Supplier
. For e.g.
@Bean
public Supplier<String> supplier() {
return () -> MessageBuilder.withPayload("Hello").build();
}
Then,
spring:
cloud:
function:
definition: supplier;consumer
stream:
bindings:
supplier-out-0:
destination: consumer-in-0
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论