Spring Cloud Stream功能支持不起作用。

huangapple go评论67阅读模式
英文:

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&lt;String&gt; consumer() {
    	return s -&gt; 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(&quot;source&quot;)
    MessageChannel producer();
}

source.producer().send(MessageBuilder.withPayload(&quot;Hello&quot;).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&lt;String&gt; supplier() {
  return () -&gt; MessageBuilder.withPayload(&quot;Hello&quot;).build();

}

Then,

spring:
    cloud:
        function:
            definition: supplier;consumer
        stream:
            bindings:
                supplier-out-0:
                    destination: consumer-in-0

huangapple
  • 本文由 发表于 2020年9月13日 01:00:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/63862797.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定