javascript
Rube GoldbergSpring整合
為了說明這一點,請考慮一個簡單的系統,該系統僅接收一條消息,然后將其發送回大寫,稱其為Echo網關:
public interface EchoGateway { String echo(String message); }并為此進行測試:
@Testpublic void testEcho() {String response = echoGateway.echo('Hello');assertThat(response, is('HELLO'));}到目前為止聽起來很簡單,使用spring集成的實現將通過轉換為大寫字母并返回增強后的消息來接受“消息”并對其進行“轉換”。
<?xml version='1.0' encoding='UTF-8'?> <beans:beans xmlns='http://www.springframework.org/schema/integration'xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'xmlns:beans='http://www.springframework.org/schema/beans'xsi:schemaLocation='http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd'><channel id='requestChannel'/><gateway id='echoGateway' service-interface='rube.simple.EchoGateway' default-request-channel='requestChannel' /><transformer input-channel='requestChannel' expression='payload.toUpperCase()' /> </beans:beans>做工精美!
Spring Integration的優點在于,即使Integration場景變得復雜,它呈現給應用程序的外觀仍然保持簡單,
考慮一個Rube Goldberg集成方案:
首先是描述旋流的圖表:
那么它到底是做什么的:
- 它接收到這樣的消息:“來自Spring整合的你好”,
- 將其拆分為單個單詞(您好,來自spring,integeg),
- 將每個單詞發送到ActiveMQ隊列,
- 從隊列中,單詞片段由濃縮器拾取以大寫每個單詞,
- 將響應放回響應隊列,
- 根據單詞的原始順序對其進行重新排序,
- 聚合成一個句子(“ HELLO FROM SPRING INTEG”),
- 返回到應用程序。
這是這種流程的Spring Integration配置的樣子:
<?xml version='1.0' encoding='UTF-8'?> <beans:beans xmlns='http://www.springframework.org/schema/integration'xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'xmlns:int-jms='http://www.springframework.org/schema/integration/jms'xmlns:beans='http://www.springframework.org/schema/beans'xsi:schemaLocation='http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsdhttp://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsdhttp://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms-2.1.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd'><beans:import resource='broker.xml'/><channel id='requestChannel'><queue/> </channel><channel id='responseChannel'><queue/></channel><gateway id='echoGateway' service-interface='rube.complicated.EchoGateway' default-request-channel='requestChannel' default-reply-channel='responseChannel' default-reply-timeout='5000' /><channel id='toJmsOutbound'/><splitter input-channel='requestChannel' output-channel='toJmsOutbound' expression='payload.split('\s')'></splitter><channel id='sequenceChannel'></channel><int-jms:outbound-gateway request-channel='toJmsOutbound' reply-channel='sequenceChannel' request-destination='amq.outbound' extract-request-payload='true' /><channel id='enhanceMessageChannel'/><channel id='toReplyQueueChannel'/><int-jms:inbound-gateway request-channel='enhanceMessageChannel' request-destination='amq.outbound' reply-channel='toReplyQueueChannel'/><transformer input-channel='enhanceMessageChannel' expression='(payload + '').toUpperCase()' output-channel='toReplyQueueChannel'/><resequencer input-channel='sequenceChannel' output-channel='aggregateChannel' release-partial-sequences='false'></resequencer><aggregator input-channel='aggregateChannel' output-channel='responseChannel' expression='T(com.google.common.base.Joiner).on(' ').join(![payload].toArray())'/><poller id='poller' fixed-delay='500' default='true'/></beans:beans>這個流程有太多的復雜性(因此Rube Goldberg),但是Spring Integration提供給應用程序的外觀仍然非常簡單。
@Testpublic void testEcho() throws Exception{String amessage = 'Hello from Spring Integration';String response = echoGateway.echo(amessage);assertThat(response, is('HELLO FROM SPRING INTEGRATION'));}我認為這是Spring Integration的本質
我在https://github.com/bijukunjummen/rg-si.git上有此代碼的github存儲庫
參考: all和其他博客中的Rube Goldberg Spring Integration,來自我們的JCG合作伙伴 Biju Kunjummen。
翻譯自: https://www.javacodegeeks.com/2012/06/rube-goldberg-spring-integration_22.html
總結
以上是生活随笔為你收集整理的Rube GoldbergSpring整合的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 火影忍者游戏电脑版好玩的游戏(火影忍者端
- 下一篇: 高达2快捷键(高达战斗行动2键位)