为什么集成流不订阅 from 频道?
Why doesn't integration flow subscribe to the from channel?
对我来说,这似乎是最简单的 spring 集成示例。我正在尝试向 si4demo 学习。但是当我 运行 它时,我得到这个异常:
Exception in thread "main"
org.springframework.messaging.MessageDeliveryException: Dispatcher has
no subscribers for channel 'application.inbox'.; nested exception is
org.springframework.integration.MessageDispatchingException:
Dispatcher has no subscribers
我哪里错了?定义的流程不会创建对收件箱频道的订阅吗?
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.messaging.MessageChannel;
@Configuration
@ComponentScan
@IntegrationComponentScan
public class App {
public static void main(String[] args) {
try (ConfigurableApplicationContext ctx = SpringApplication.run(App.class, args)) {
final Gateway gateway = ctx.getBean(Gateway.class);
final String rs = gateway.send("hullo");
System.out.println(rs);
}
}
private static final String INBOX = "inbox";
@MessagingGateway(defaultRequestChannel = INBOX)
public interface Gateway {
String send(String msg);
}
@Bean
public IntegrationFlow flow() {
return IntegrationFlows.from(INBOX)
.transform(p -> "world")
.get();
}
@Bean(name = INBOX)
public MessageChannel inbox() {
return new DirectChannel();
}
}
看起来你错过了主要玩家 - @EnableIntegraion
:
Starting with version 4.0, the @EnableIntegration
annotation has been introduced, to allow the registration of Spring Integration infrastructure beans (see JavaDocs). This annotation is required when only Java & Annotation configuration is used, e.g. with Spring Boot and/or Spring Integration Messaging Annotation support and Spring Integration Java DSL with no XML integration configuration.
对我来说,这似乎是最简单的 spring 集成示例。我正在尝试向 si4demo 学习。但是当我 运行 它时,我得到这个异常:
Exception in thread "main" org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'application.inbox'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
我哪里错了?定义的流程不会创建对收件箱频道的订阅吗?
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.messaging.MessageChannel;
@Configuration
@ComponentScan
@IntegrationComponentScan
public class App {
public static void main(String[] args) {
try (ConfigurableApplicationContext ctx = SpringApplication.run(App.class, args)) {
final Gateway gateway = ctx.getBean(Gateway.class);
final String rs = gateway.send("hullo");
System.out.println(rs);
}
}
private static final String INBOX = "inbox";
@MessagingGateway(defaultRequestChannel = INBOX)
public interface Gateway {
String send(String msg);
}
@Bean
public IntegrationFlow flow() {
return IntegrationFlows.from(INBOX)
.transform(p -> "world")
.get();
}
@Bean(name = INBOX)
public MessageChannel inbox() {
return new DirectChannel();
}
}
看起来你错过了主要玩家 - @EnableIntegraion
:
Starting with version 4.0, the
@EnableIntegration
annotation has been introduced, to allow the registration of Spring Integration infrastructure beans (see JavaDocs). This annotation is required when only Java & Annotation configuration is used, e.g. with Spring Boot and/or Spring Integration Messaging Annotation support and Spring Integration Java DSL with no XML integration configuration.