日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Rube GoldbergSpring整合

發(fā)布時間:2023/12/3 javascript 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Rube GoldbergSpring整合 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Spring Integration為集成系統(tǒng)所涉及的某些復(fù)雜性提供了非常好的抽象-Spring Integration從Integration的角度來看非常適合Facade的定義-簡化了對復(fù)雜底層系統(tǒng)的訪問。

為了說明這一點,請考慮一個簡單的系統(tǒng),該系統(tǒng)僅接收一條消息,然后將其發(fā)送回大寫,稱其為Echo網(wǎng)關(guān):

public interface EchoGateway { String echo(String message); }

并為此進行測試:

@Testpublic void testEcho() {String response = echoGateway.echo('Hello');assertThat(response, is('HELLO'));}

到目前為止聽起來很簡單,使用spring集成的實現(xiàn)將通過轉(zhuǎn)換為大寫字母并返回增強后的消息來接受“消息”并對其進行“轉(zhuǎn)換”。

<?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的優(yōu)點在于,即使Integration場景變得復(fù)雜,它呈現(xiàn)給應(yīng)用程序的外觀仍然保持簡單,

考慮一個Rube Goldberg集成方案:

首先是描述旋流的圖表:

那么它到底是做什么的:

  • 它接收到這樣的消息:“來自Spring整合的你好”,
  • 將其拆分為單個單詞(您好,來自spring,integeg),
  • 將每個單詞發(fā)送到ActiveMQ隊列,
  • 從隊列中,單詞片段由濃縮器拾取以大寫每個單詞,
  • 將響應(yīng)放回響應(yīng)隊列,
  • 根據(jù)單詞的原始順序?qū)ζ溥M行重新排序,
  • 聚合成一個句子(“ HELLO FROM SPRING INTEG”),
  • 返回到應(yīng)用程序。

這是這種流程的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>

這個流程有太多的復(fù)雜性(因此Rube Goldberg),但是Spring Integration提供給應(yīng)用程序的外觀仍然非常簡單。

@Testpublic void testEcho() throws Exception{String amessage = 'Hello from Spring Integration';String response = echoGateway.echo(amessage);assertThat(response, is('HELLO FROM SPRING INTEGRATION'));}

我認(rèn)為這是Spring Integration的本質(zhì)

我在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

總結(jié)

以上是生活随笔為你收集整理的Rube GoldbergSpring整合的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。