我可能只是在這裏錯過了一些非常簡單的東西(或者誤用了某些東西),但我試圖設置兩個直接通道,以便一個流將一些數據依次傳遞給每個通道。因此,使用Spring集成JAVA DSL我有這樣的事情(顯著簡化了這個例子):春天集成通道鏈接奇怪
public static final String TEST_CHANNEL = "testGateway";
public static final String TEST_UPPER_CHANNEL = "testChannelUpper";
public static final String TEST_LOWER_CHANNEL = "testChannelLower";
@Bean(name = TEST_CHANNEL)
public MessageChannel testGatewayChannel() {
return MessageChannels.direct(TEST_CHANNEL).get();
}
@Bean(name = TEST_UPPER_CHANNEL)
public MessageChannel testChannelUpperChannel() {
return MessageChannels.direct(TEST_UPPER_CHANNEL).get();
}
@Bean(name = TEST_LOWER_CHANNEL)
public MessageChannel testChannelLowerChannel() {
return MessageChannels.direct(TEST_LOWER_CHANNEL).get();
}
@Bean
public IntegrationFlow testFlow() {
return IntegrationFlows
.from(TEST_CHANNEL)
.channel(TEST_UPPER_CHANNEL)
.channel(TEST_LOWER_CHANNEL)
.get();
}
@Bean
public IntegrationFlow testUpperFlow() {
return IntegrationFlows
.from(TEST_UPPER_CHANNEL)
.<String, String>transform(String::toUpperCase)
.handle(System.out::println)
.get();
}
@Bean
public IntegrationFlow testLowerFlow() {
return IntegrationFlows
.from(TEST_LOWER_CHANNEL)
.<String, String>transform(String::toLowerCase)
.handle(System.out::println)
.get();
}
我使用REST端點調用通過網關的流量,但是當我這樣做似乎只其中一個通道被調用。該頻道在調用中似乎也是隨機的(有時會轉到testChannelUpper,有時轉到testChannelLower)。
我基本上與此最終跨越執行: (每次我只擊中該端點http://localhost:9090/test?test=HellOoi)
執行1: GenericMessage [有效載荷= HELLOOI,標頭= {JOBNAME = someActivity ,歷史= someGateway,testGateway,testChannelUpper,testUpperFlow.channel#0,ID = 4aa7b075-23cc-6ab3-10a1-c7cb73bae49b,時間戳= 1447686848477}]
執行2: GenericMessage [有效載荷= HELLOOI,標頭= {JOBNAME = someActivity,歷史= someGateway,testGateway,testChannelUpper,testUpperFlow.channel#0,ID = a18dcd01-DA18-b00d-30c0-e1a03ce19104,時間戳= 1447686853549}]
執行3: GenericMessage [有效載荷= hellooi,標頭= {JOBNAME = someActivity,歷史= someGateway,testGateway,testChannelUpper,testLowerFlow.channel#0,ID = 5f0abcb9-378e-7a3c-9c93-a04ff6352927,時間戳= 1447686857545}]
我相信我在這裏嘗試的也是在DSL wiki的channelFlow示例中顯示的: 級https://github.com/spring-projects/spring-integration-java-dsl/wiki/Spring-Integration-Java-DSL-Reference
的sooo上我使用的是什麼樣的規格是:
春季啓動v1.2.2.RELEASE
春v4.1.5.RELEASE
彈簧集成的Java-DSL 1.0 .2.RELEASE
JDK 1.8.0_40-b25的
所以......已經沒有其他人看到這種行爲?我是否濫用渠道實施?任何其他想法?提前致謝!
正如加里指出,要做到這一點的最好辦法是有一個酒吧-Sub和訂購的消費者對這樣的:
@Bean(name = TEST_CHANNEL)
public MessageChannel testGatewayChannel() {
return MessageChannels.publishSubscribe(TEST_CHANNEL).get();
}
@Bean
public IntegrationFlow testUpperFlow() {
return IntegrationFlows
.from(TEST_CHANNEL)
.<String, String>transform(String::toUpperCase, e -> e.order(1))
.handle(System.out::println)
.get();
}
@Bean
public IntegrationFlow testLowerFlow() {
return IntegrationFlows
.from(TEST_CHANNEL)
.<String, String>transform(String::toLowerCase, e -> e.order(2))
.handle(System.out::println)
.get();
}
嘿加里...我的意圖是讓消息前往兩個頻道(** TEST_CHANNEL ** - > ** TEST_UPPER_CHANNEL ** - > ** TEST_LOWER_CHANNEL **)。我不確定我是否將此問題與fixedSubscriberChannel混淆,但這不是必需的,我將其從帖子中刪除。 – Tristan
那是不對的;你可以簡單地把'TEST_CHANNEL'改成'MessageChannels.publishSubscribe()。get'(或'return new PublishSubscribeChannel()');然後簡單地將每個流程改爲'from(TEST_CHANNEL)';消除'testFlow()'。 –
是的。我知道你在做什麼,但我希望能夠按順序執行這些頻道。我對多通道設置工作方式的假設顯然是錯誤的。 (我會弄明白的,但是要感謝您的輸入! – Tristan