我有这样的 PublishSubscribeChannel:
@Bean(name = {"publishCha.input", "publishCha2.input"}) //2 subscribers
public MessageChannel publishAction() {
PublishSubscribeChannel ps = MessageChannels.publishSubscribe().get();
ps.setMaxSubscribers(8);
return ps;
}
我也有订阅者频道:
@Bean
public IntegrationFlow publishCha() {
return f -> f
.handle(m -> System.out.println("In publishCha channel..."));
}
@Bean
public IntegrationFlow publishCha2() {
return f -> f
.handle(m -> System.out.println("In publishCha2 channel..."));
}
最后是另一个订阅者:
@Bean
public IntegrationFlow anotherChannel() {
return IntegrationFlows.from("publishAction")
.handle(m -> System.out.println("ANOTHER CHANNEL IS HERE!"))
.get();
}
问题是,当我从另一个流程中调用方法名称为“publishAction”的频道时,它只打印“ANOTHER CHANNEL HERE”并忽略其他订阅者。但是,如果我用 调用
.channel("publishCha.input")
,这次它会进入 publishCha 和 publishCha2 订阅者,但会忽略第三个订阅者。
@Bean
public IntegrationFlow flow() {
return f -> f
.channel("publishAction");
}
我的问题是,为什么这两种不同的引导方法会产生不同的结果?
.channel("publishAction") // channeling with method name executes third subscriber
.channel("publishCha.input") // channelling with bean name, executes first and second subscribers
编辑:narayan-sambireddy 询问我如何向频道发送消息。我通过网关发送它:
@MessagingGateway
public interface ExampleGateway {
@Gateway(requestChannel = "flow.input")
void flow(Order orders);
}
在主要:
Order order = new Order();
order.addItem("PC", "TTEL", 2000, 1)
ConfigurableApplicationContext ctx = SpringApplication.run(Start.class, args);
ctx.getBean(ExampleGateway.class).flow(order);