ï»??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美天堂影院,一区二区三区在线免费观看,三级视频网站在线http://www.aygfsteel.com/paulwong/category/51928.htmlzh-cnFri, 21 Jan 2022 02:24:41 GMTFri, 21 Jan 2022 02:24:41 GMT60SPRING INTEGRATION - 集群选主、分布式é”?/title><link>http://www.aygfsteel.com/paulwong/archive/2022/01/20/439381.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Thu, 20 Jan 2022 05:49:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2022/01/20/439381.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/439381.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2022/01/20/439381.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/439381.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/439381.html</trackback:ping><description><![CDATA[集群通常是有多个相同的实例,但对于定时ä“Q务场景,只希望有一个实例工作即可,如果˜q™ä¸ªå®žä¾‹æŒ‚了åQŒå…¶ä»–实例可以顶æ›Ñ€?br /><br />˜q™ä¸ªé—®é¢˜çš„æ–¹æ¡ˆåˆ™æ˜¯é›†¾Ÿ¤é€‰ä¸»åQŒä¸€ä¸ªé›†¾Ÿ¤ä¸­åQŒåªæœ‰ä¸€ä¸ªLEADERåQŒç”±LEADER负责执行定时ä»ÕdŠ¡å·¥ä½œã€‚å½“LEADER被取消时åQŒä¼šåœ¨å‰©ä¸‹çš„实例中再选LEADERã€?br /><br />持有分布式锁的实例则是LEADERã€?br /><br />SPRING INTEGRATION JDBC åˆ™å·²æä¾›ç›¸å…³åŠŸèƒ½ã€?br /><br />pom.xml<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->        <span style="color: #0000FF; "><</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">></span><br />           <span style="color: #0000FF; "><</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">></span>org.springframework.integration<span style="color: #0000FF; "></</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">></span><br />           <span style="color: #0000FF; "><</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">></span>spring-integration-jdbc<span style="color: #0000FF; "></</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">></span><br />        <span style="color: #0000FF; "></</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">></span><br /><br />        <span style="color: #0000FF; "><</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">></span><br />            <span style="color: #0000FF; "><</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">></span>org.springframework.boot<span style="color: #0000FF; "></</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">></span><br />            <span style="color: #0000FF; "><</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">></span>spring-boot-starter-jdbc<span style="color: #0000FF; "></</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">></span><br />        <span style="color: #0000FF; "></</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">></span><br /><br />        <span style="color: #0000FF; "><</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">></span><br />           <span style="color: #0000FF; "><</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">></span>org.flywaydb<span style="color: #0000FF; "></</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">></span><br />           <span style="color: #0000FF; "><</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">></span>flyway-core<span style="color: #0000FF; "></</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">></span><br />        <span style="color: #0000FF; "></</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">></span><br />        <br />        <span style="color: #0000FF; "><</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">></span><br />            <span style="color: #0000FF; "><</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">></span>org.mariadb.jdbc<span style="color: #0000FF; "></</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">></span><br />            <span style="color: #0000FF; "><</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">></span>mariadb-java-client<span style="color: #0000FF; "></</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">></span><br />        <span style="color: #0000FF; "></</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">></span></div><br />LeaderElectionIntegrationConfig.java<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">import</span> java.util.List;<br /><span style="color: #0000FF; ">import</span> java.util.concurrent.CopyOnWriteArrayList;<br /><br /><span style="color: #0000FF; ">import</span> javax.sql.DataSource;<br /><br /><span style="color: #0000FF; ">import</span> org.springframework.context.annotation.Bean;<br /><span style="color: #0000FF; ">import</span> org.springframework.context.annotation.Configuration;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.jdbc.lock.DefaultLockRepository;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.jdbc.lock.JdbcLockRegistry;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.jdbc.lock.LockRepository;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.support.leader.LockRegistryLeaderInitiator;<br /><br /><span style="color: #0000FF; ">import</span> com.paul.integration.leader.ControlBusGateway;<br /><span style="color: #0000FF; ">import</span> com.paul.integration.leader.MyCandidate;<br /><br />@Configuration<br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> LeaderElectionIntegrationConfig {<br />    <br />    @Bean<br />    <span style="color: #0000FF; ">public</span> List<String> needToStartupAdapterList(){<br />        <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">new</span> CopyOnWriteArrayList<>();<br />    }<br />    <br />    @Bean<br />    <span style="color: #0000FF; ">public</span> DefaultLockRepository defaultLockRepository(DataSource dataSource){<br />        DefaultLockRepository defaultLockRepository =<br />                <span style="color: #0000FF; ">new</span> DefaultLockRepository(dataSource);<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">        defaultLockRepository.setTimeToLive(60_000);</span><span style="color: #008000; "><br /></span>        <span style="color: #0000FF; ">return</span> defaultLockRepository;<br />    }<br /><br />    @Bean<br />    <span style="color: #0000FF; ">public</span> JdbcLockRegistry jdbcLockRegistry(LockRepository lockRepository){<br />        <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">new</span> JdbcLockRegistry(lockRepository);<br />    }<br />    <br />    @Bean<br />    <span style="color: #0000FF; ">public</span> MyCandidate myCandidate(<br />        ControlBusGateway controlBusGateway,<br />        List<String> needToStartupAdapterList<br />    ) {<br />        <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">new</span> MyCandidate(controlBusGateway, needToStartupAdapterList);<br />    }<br />    <br />    @Bean<br />    <span style="color: #0000FF; ">public</span> LockRegistryLeaderInitiator leaderInitiator() {<br />        <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">new</span> LockRegistryLeaderInitiator(<br />                    jdbcLockRegistry(<span style="color: #0000FF; ">null</span>), myCandidate(<span style="color: #0000FF; ">null</span>, <span style="color: #0000FF; ">null</span>)<br />               );<br />    }<br />    <br />    <br />}</div><br /><br /><div>MyCandidate.java</div><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">import</span> java.util.List;<br /><br /><span style="color: #0000FF; ">import</span> org.slf4j.Logger;<br /><span style="color: #0000FF; ">import</span> org.slf4j.LoggerFactory;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.leader.Context;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.leader.DefaultCandidate;<br /><br /><span style="color: #0000FF; ">import</span> com.novacredit.mcra.mcracommon.integration.gateway.ControlBusGateway;<br /><br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> MyCandidate <span style="color: #0000FF; ">extends</span> DefaultCandidate{<br />    <br />    <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">static</span> <span style="color: #0000FF; ">final</span> Logger LOG = LoggerFactory.getLogger(MyCandidate.<span style="color: #0000FF; ">class</span>);<br />    <br />    <span style="color: #0000FF; ">private</span> List<String> needToStartupAdapterList;<br />    <br />    <span style="color: #0000FF; ">private</span> ControlBusGateway controlBusGateway;<br />    <br />    <span style="color: #0000FF; ">public</span> MyCandidate(<br />        ControlBusGateway controlBusGateway,<br />        List<String> needToStartupAdapterList<br />    ) {<br />        <span style="color: #0000FF; ">this</span>.controlBusGateway = controlBusGateway;<br />        <span style="color: #0000FF; ">this</span>.needToStartupAdapterList = needToStartupAdapterList;<br />    }<br />    <br />    @Override<br />    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">void</span> onGranted(Context context) {<br />        <span style="color: #0000FF; ">super</span>.onGranted(context);<br />        LOG.info("*** Leadership granted ***");<br />        LOG.info("STARTING MONGODB POLLER");<br />        needToStartupAdapterList<br />            .forEach(<br />                c -> {<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">                    c = "@'testIntegrationFlow.org.springframework.integration.config."<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">                            + "SourcePollingChannelAdapterFactoryBean#0'";</span><span style="color: #008000; "><br /></span>                    String command = c + ".start()";<br />                    LOG.info("-----{}", command);<br />                    controlBusGateway.sendCommand(command);<br />                }<br />             );<br />        LOG.info("STARTUP MESSAGE SENT");<br /><br />    }<br /><br />    @Override<br />    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">void</span> onRevoked(Context context) {<br />        <span style="color: #0000FF; ">super</span>.onRevoked(context);<br />        LOG.info("*** Leadership revoked ***");<br />        LOG.info("STOPPING MONGODB POLLER");<br />        needToStartupAdapterList<br />            .forEach(<br />                c -> {<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">                    c = "@'testIntegrationConfig.testIntegrationFlow."<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">                            + "mongoMessageSource.inboundChannelAdapter'";</span><span style="color: #008000; "><br /></span>                    String command = c + ".stop()";<br />                    LOG.info("-----{}", command);<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">                    controlBusGateway.sendCommand(command);</span><span style="color: #008000; "><br /></span>                }<br />             );<br />        LOG.info("SHUTDOWN MESSAGE SENT");<br />    }<br /><br />}</div><br /><br />ControlBusIntegrationConfig.java<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">import</span> org.springframework.context.annotation.Bean;<br /><span style="color: #0000FF; ">import</span> org.springframework.context.annotation.Configuration;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.dsl.IntegrationFlow;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.dsl.IntegrationFlows;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.dsl.MessageChannels;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.gateway.GatewayProxyFactoryBean;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.handler.LoggingHandler;<br /><span style="color: #0000FF; ">import</span> org.springframework.messaging.MessageChannel;<br /><br /><span style="color: #0000FF; ">import</span> com.paul.integration.gateway.ControlBusGateway;<br /><br />@Configuration<br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> ControlBusIntegrationConfig {<br />    <br />    @Bean<br />    <span style="color: #0000FF; ">public</span> MessageChannel controlBusChannel() {<br />        <span style="color: #0000FF; ">return</span> MessageChannels.direct().get();<br />    }<br />    <br />    @Bean<br />    <span style="color: #0000FF; ">public</span> IntegrationFlow controlBusFlow() {<br />        <span style="color: #0000FF; ">return</span> IntegrationFlows.from(controlBusChannel())<br />                    .log(LoggingHandler.Level.INFO, "controlBusChannel")<br />                    .controlBus()<br />                    .get();<br />    }<br />    <br />    @Bean<br />    <span style="color: #0000FF; ">public</span> GatewayProxyFactoryBean controlBusGateway() {<br />        GatewayProxyFactoryBean gateway = <span style="color: #0000FF; ">new</span> GatewayProxyFactoryBean(ControlBusGateway.<span style="color: #0000FF; ">class</span>);<br />        gateway.setDefaultRequestChannel(controlBusChannel());<br />        gateway.setDefaultRequestTimeout(300l);<br />        gateway.setDefaultReplyTimeout(300l);<br />        <span style="color: #0000FF; ">return</span> gateway;<br />    }<br />    <br />}</div><br /><br />ControlBusGateway.java<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">interface</span> ControlBusGateway {<br />    <br />    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">void</span> sendCommand(String command);<br /><br />}</div><br /><br />各个应用实例˜qè¡Œæ—Óž¼Œå…¶ä¸­çš„LockRegistryLeaderInitiator会自动运行,抢夺LEADER数据åQŒæœ€¾lˆåªæœ‰ä¸€ä¸ªå®žä¾‹å¤ºå–。之后再执行MyCandidate中的代码ã€?br /><br /><br /><br /><br /><br /><br /><br /><img src ="http://www.aygfsteel.com/paulwong/aggbug/439381.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2022-01-20 13:49 <a href="http://www.aygfsteel.com/paulwong/archive/2022/01/20/439381.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>EVEN DRIVEN - SPRING CLOUD STREAM 3.x - Functional Programming Modelhttp://www.aygfsteel.com/paulwong/archive/2021/11/10/436035.htmlpaulwongpaulwongWed, 10 Nov 2021 07:10:00 GMThttp://www.aygfsteel.com/paulwong/archive/2021/11/10/436035.htmlhttp://www.aygfsteel.com/paulwong/comments/436035.htmlhttp://www.aygfsteel.com/paulwong/archive/2021/11/10/436035.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/436035.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/436035.htmlSPRING CLOUD STREAM 3.x ç‰ˆæœ¬æ—Óž¼Œä¹‹å‰çš„一些编½E‹æ¨¡å¼ï¼Œå¦‚@EnablebinddingåQŒ@StreamListenner½{‰æ³¨é‡Šè¢«åºŸå¼ƒäº†ï¼Œ˜q™æ˜¯ç”׃ºŽä¸€äº›æ¡†æž¶çš„代码必需ç”Þq”¨æˆïL¼–写,如配¾|®æ¡†æž¶ç”¨çš„Input MessageChannelåQŒOutput  MessageChannelåQŒè¿žæŽ¥MessageHandler与MessageChannel½{‰ï¼Œè¢«è§†ä¸ÞZ¸å¿…è¦çš„åŠ¨ä½œã€‚äØ“äº†ç®€åŒ–ç”¨æˆ·ä»£ç ï¼ŒäºŽæ˜¯æŽ¨å‡ºFunctional Programming Modelã€?br />
引入了新名词åQšSupplier、Function与Consumer。实际上˜q™å‡ ä¸ªç±»å¯è§†ä¸ºAdapteråQŒå¦‚果之前已¾læœ‰å­˜åœ¨çš„Service¾c»ï¼Œä¸”方法名为各¿Uå„æ øP¼Œå¯ä»¥é‡æ–°åŒ…装成Supplier、Function与ConsumeråQŒåƈ在固定的æ–ÒŽ³•名:apply/get/accept中调用Service的方法ã€?br />

Supplier

当在配置文äšg中注入此¾cÕdž‹çš„BeanåQŒåƈ在spring.cloud.stream.function.definition加入此Bean的名¿UŽÍ¼ŒSPRING CLOUD STREAMž®×ƒ¼šå¸®ä½ ç”Ÿæˆä¸€ä¸ªOutput  MessageChannelåQŒåƈ˜qžæŽ¥ä¸Šæ­¤BeanåQŒåŽ¾l­åªéœ€è¦åœ¨BINDDING中加入对应的Destination NameåQŒå³å¯å‘BROKER发消息了ã€?br />

Consumer

当在配置文äšg中注入此¾cÕdž‹çš„BeanåQŒåƈ在spring.cloud.stream.function.definition加入此Bean的名¿UŽÍ¼ŒSPRING CLOUD STREAMž®×ƒ¼šå¸®ä½ ç”Ÿæˆä¸€ä¸ªInput  MessageChannelåQŒåƈ˜qžæŽ¥ä¸Šæ­¤BeanåQŒåŽ¾l­åªéœ€è¦åœ¨BINDDING中加入对应的Destination NameåQŒå³å¯æ”¶åˆ°BROKER推送关于此Destination的消息了ã€?br />

Function

当在配置文äšg中注入此¾cÕdž‹çš„BeanåQŒåƈ在spring.cloud.stream.function.definition加入此Bean的名¿UŽÍ¼ŒSPRING CLOUD STREAMž®×ƒ¼šå¸®ä½ ç”Ÿæˆä¸€ä¸ªInputå’ŒOutput  MessageChannelåQŒåƈ˜qžæŽ¥ä¸Šæ­¤BeanåQŒåŽ¾l­åªéœ€è¦åœ¨BINDDING中分别对Inputå’ŒOutput MessageChannel加入对应的Destination Name1/Name2åQŒå³å¯æ”¶åˆ°BROKER推送关于此Destination的消息,也可以向BROKER发消息了ã€?br />

与SPRING INTEGRATION的整å?/h2>如果要对消息˜q›è¡Œå¤æ‚处理åQŒå¦‚拆分消息、聚合消息、IF ELSE消息½{‰ï¼Œž®Þp¦å€ŸåŠ©SPRING INTEGRATION了ã€?br />
@Bean
    public IntegrationFlow upperCaseFlow(LoanService loanService) {
        return IntegrationFlows
                    //turn this IntegrationFlow as a gateway, here is a Function interface 
                    
//with loadCheckerFunction as bean name
                    .from(LoadCheckerFunction.class, gateway -> gateway.beanName("loadCheckerFunction"))
                    .handle(loanService, "check")
                    .logAndReply(LoggingHandler.Level.WARN);
    }

    public interface LoadCheckerFunction extends Function<Loan, Loan>{

    }

IntegrationFlows.from(Class<?> serviceInterface)是可以将本IntegrationFlow包装成serviceInterface的实现类åQŒå¦‚果调用此接口åQŒæœ€¾lˆä¼š˜q”回IntegrationFlow最后一个步骤的实体åQŒå¦‚果这个serviceInterface是Function的话åQŒåˆšå¥½å’ŒSPRING CLOUD STREAMå¯ÒŽŽ¥ä¸Šã€?br />
后箋在spring.cloud.stream.function.definition加入此Bean的名¿U°loadCheckerFunctionåQŒSPRING CLOUD STREAMž®×ƒ¼šå¸®ä½ ç”Ÿæˆä¸€ä¸ªInputå’ŒOutput  MessageChannelåQŒåƈ˜qžæŽ¥ä¸Šæ­¤BeanåQŒå†åœ¨BINDDING中分别对Inputå’ŒOutput MessageChannel加入对应的Destination Name1/Name2åQŒå³å¯æ”¶åˆ°BROKER推送关于此Destination的消息,也可以向BROKER发消息ã€?br />
application.yaml
# This setting can increase or decrease the rate of message production (1000 = 1s)
# spring.cloud.stream.poller.fixed-delay=1000

# This setting can control which function method in our code will be triggered if there are multiple
# spring.cloud.function.definition=supplyLoan

# Give the autogenerated binding a friendlier name

spring:
   application:
      name: loan-check-rabbit
   banner:
      location: classpath:/banner-rabbit.txt
   cloud:
      stream:
         function.definition: loadCheckerFunction
         #BindingProperties
         bindings:
            loadCheckerFunction-in-0:
               destination: queue.pretty.log.messages
               binder: local_rabbit
            loadCheckerFunction-out-0:
               destination: queue.pretty.approved.messages
               binder: local_rabbit
         #BinderProperties
         binders:
            local_rabbit:
               type: rabbit
               environment:
                  spring:
                     rabbitmq:
                        host: 10.80.27.69
                        port: 5672
                        username: guest
                        password: guest
                        virtual-host: my-virtual-host

Reference

https://spring.io/blog/2019/10/25/spring-cloud-stream-and-spring-integration

]]>
SPRING INTEGRATION - ENRICHhttp://www.aygfsteel.com/paulwong/archive/2021/09/21/435976.htmlpaulwongpaulwongTue, 21 Sep 2021 05:40:00 GMThttp://www.aygfsteel.com/paulwong/archive/2021/09/21/435976.htmlhttp://www.aygfsteel.com/paulwong/comments/435976.htmlhttp://www.aygfsteel.com/paulwong/archive/2021/09/21/435976.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435976.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435976.html
package org.springframework.integration.stackoverflow.enricher;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.dsl.Transformers;
import org.springframework.integration.http.dsl.Http;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
public class SpringIntegrationEnricherApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringIntegrationEnricherApplication.class, args);
    }

    @Bean
    public IntegrationFlow jsonEnricherFlow(RestTemplate restTemplate) {
        return IntegrationFlows.from(Function.class)
                .transform(Transformers.fromJson(Map.class))
                .enrich((enricher) -> enricher
                        .<Map<String, ?>>requestPayload((message) ->
                                ((List<?>) message.getPayload().get("attributeIds"))
                                        .stream()
                                        .map(Object::toString)
                                        .collect(Collectors.joining(",")))
                        .requestSubFlow((subFlow) ->
                                subFlow.handle(
                                        Http.outboundGateway("/attributes?id={ids}", restTemplate)
                                                .httpMethod(HttpMethod.GET)
                                                .expectedResponseType(Map.class)
                                                .uriVariable("ids", "payload")))
                        .propertyExpression("attributes", "payload.attributes"))
                .<Map<String, ?>, Map<String, ?>>transform(
                        (payload) -> {
                            payload.remove("attributeIds");
                            return payload;
                        })
                .transform(Transformers.toJson())
                .get();
    }

}

https://stackoverflow.com/questions/58205432/spring-integration-enrich-transform-message-using-rest-call

https://www.tabnine.com/web/assistant/code/rs/5c781b6ae70f87000197ab9f#L312



]]>
SPRING INTEGRATION RETRYhttp://www.aygfsteel.com/paulwong/archive/2021/08/23/435950.htmlpaulwongpaulwongMon, 23 Aug 2021 05:01:00 GMThttp://www.aygfsteel.com/paulwong/archive/2021/08/23/435950.htmlhttp://www.aygfsteel.com/paulwong/comments/435950.htmlhttp://www.aygfsteel.com/paulwong/archive/2021/08/23/435950.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435950.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435950.html 默认是重è¯?‹Æ¡ï¼Œæ¯æ¬¡é‡è¯•é—´éš”æ˜?0¿U’ã€?br />
@SpringBootApplication
public class SpringIntegrationDslHttpRetryApplication {

    @SuppressWarnings("unchecked")
    public static void main(String[] args) {
        ConfigurableApplicationContext applicationContext =
                SpringApplication.run(SpringIntegrationDslHttpRetryApplication.class, args);
        Function<Object, Object> function = applicationContext.getBean(Function.class);
        function.apply("foo");
    }

    @Bean
    public IntegrationFlow httpRetryFlow() {
        return IntegrationFlows.from(Function.class)
                .handle(Http.outboundGateway("http://localhost:11111")
                                .httpMethod(HttpMethod.GET)
                                .expectedResponseType(String.class),
                        e -> e.advice(retryAdvice()))
                .get();
    }

    @Bean
    public RequestHandlerRetryAdvice retryAdvice() {
        return new RequestHandlerRetryAdvice();
    }

}

#打印日志
logging.level.org.springframework.retry=debug

Reference:
https://docs.spring.io/spring-integration/reference/html/handler-advice.html#retry-advice
https://stackoverflow.com/questions/49784360/configure-error-handling-and-retry-for-http-outboundgateway-spring-dsl
https://stackoverflow.com/questions/50262862/requesthandlerretryadvice-with-httprequestexecutingmessagehandler-not-working
https://stackoverflow.com/questions/63689856/spring-integration-http-outbound-gateway-retry-based-on-reply-content
https://blog.csdn.net/cunfen8879/article/details/112552420




]]>
JSR-303 Bean Validationhttp://www.aygfsteel.com/paulwong/archive/2021/01/28/435786.htmlpaulwongpaulwongThu, 28 Jan 2021 02:35:00 GMThttp://www.aygfsteel.com/paulwong/archive/2021/01/28/435786.htmlhttp://www.aygfsteel.com/paulwong/comments/435786.htmlhttp://www.aygfsteel.com/paulwong/archive/2021/01/28/435786.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435786.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435786.html
JSR-303 Bean Validation则提供了˜q™æ ·çš„便捗÷€?br />
只要在JAVA BEAN中需要验证的字段加@NotNull˜q™ç§æ ‡ç­¾åQŒç„¶åŽåœ¨SERVISE中的输入参数中加@Valid标签åQŒåˆ™ž®±æ¿€‹z»éªŒè¯æµ½E‹ã€?br />也可以编½E‹çš„æ–¹å¼è‡ªå·±éªŒè¯åQ?br />
@MessageEndpoint
//@Validated
public class MqMessageCcdValidator {
    
    private static final Logger LOGGER = LoggerFactory.getLogger(MqMessageCcdValidator.class);
    
    @Autowired
    private Validator validator;
    
    @ServiceActivator
    public MqMessage<CcdRequest> validate(/* @Valid */ Message<MqMessage<CcdRequest>> requestMessage) {
        Set<ConstraintViolation<MqMessage<CcdRequest>>> set = validator.validate(requestMessage.getPayload());
        if(CollectionUtils.isNotEmpty(set)) {
            CompositeException compositeException = new CompositeException();
            set.forEach(
                constraintViolation -> {
                                            LOGGER.info("{}", constraintViolation);
                                            ReqInfoValidationException exception =
                                                    new ReqInfoValidationException(constraintViolation.getMessage());
                                            compositeException.addException(exception);
                                       }
            );
            throw new MessageHandlingException(requestMessage, compositeException);
        }
        
        return requestMessage.getPayload();
    }

}

自定义验证规åˆ?br />可用标签来做åQŒä»¥ä¸‹äؓ验证手机åïLš„规则åQ?br />
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.ReportAsSingleViolation;
import javax.validation.constraints.Pattern;

@Retention(RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE })
@Constraint(validatedBy = {})
@ReportAsSingleViolation
@Pattern(regexp = "^1[3-9]\\d{9}$")
public @interface ChinaPhone {
    String message() default "Invalid Chinese mobile No.";
    Class<?>[] groups() default {};
    Class<? extends Payload>[] payload() default {};
}

如果比较复杂的验证规则,则参见:
https://reflectoring.io/bean-validation-with-spring-boot/#implementing-a-custom-validator

How to use Java Bean Validation in Spring Boot
https://nullbeans.com/how-to-use-java-bean-validation-in-spring-boot/

Complete Guide to Validation With Spring Boot
https://reflectoring.io/bean-validation-with-spring-boot/

Spring JMS Validate Messages using JSR-303 Bean Validation
https://memorynotfound.com/spring-jms-validate-messages-jsr-303-bean-validation/

Spring REST Validation Example
https://mkyong.com/spring-boot/spring-rest-validation-example/

Spring Boot 整合 Bean Validation 校验数据

https://blog.csdn.net/wangzhihao1994/article/details/108403732


]]>
SPRING INTEGRATION SCATTERGATHERhttp://www.aygfsteel.com/paulwong/archive/2021/01/28/435785.htmlpaulwongpaulwongThu, 28 Jan 2021 02:11:00 GMThttp://www.aygfsteel.com/paulwong/archive/2021/01/28/435785.htmlhttp://www.aygfsteel.com/paulwong/comments/435785.htmlhttp://www.aygfsteel.com/paulwong/archive/2021/01/28/435785.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435785.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435785.html
  1. 食客下单åQŒæœ‰é¥®å“ã€é£Ÿç‰©ã€ç”œç‚?br />
  2. 侍应接单åQŒä¼ é€ç»™åŽ¨æˆ¿
  3. 厨房分三个子‹¹ç¨‹å¤„理åQŒå³é¥®å“ã€é£Ÿç‰©ã€ç”œç‚¹å­‹¹ç¨‹
  4. ½{‰å¾…三个子流½E‹å¤„理完åQŒåˆòq¶æˆä¸€ä»½äº¤ä»?
  5. 如果厨房发现某食物欠¾~ºï¼Œä¼šé€šçŸ¥ä¾åº”åQŒå±•开错误处理åQŒå³é€šçŸ¥é£Ÿå®¢æ›´æ”¹é£Ÿç‰©åQŒå†äº¤ç»™åŽ¨æˆ¿
  6. 侍应ž®†äº¤ä»˜å“ä¼ é€ç»™é£Ÿå®¢
有一个主‹¹ç¨‹ã€ä¸‰ä¸ªå­‹¹ç¨‹å’Œä¸€ä¸ªèšåˆæµ½E‹ï¼Œèšåˆ‹¹ç¨‹ä¼šèšåˆä¸‰ä¸ªå­‹¹ç¨‹çš„äñ”物,通知ä¸ÀLµ½E‹ï¼Œå†å¾€ä¸‹èµ°ã€?br />òq¶ä¸”ä¸ÀLµ½E‹ä¼šæ„ŸçŸ¥å­æµ½E‹çš„错误åQŒåƈ会交¾l™ç›¸åº”错误处理流½E‹å¤„理,且将¾l“果再交¾l™èšåˆæµ½E‹ã€?br />
对应SPRING INTEGRATION çš„SCATTERGATHER模式åQ?br />
@Bean
public IntegrationFlow scatterGatherAndExecutorChannelSubFlow(TaskExecutor taskExecutor) {
    return f -> f
            .scatterGather(
                    scatterer -> scatterer
                            .applySequence(true)
                            .recipientFlow(f1 -> f1.transform(p -> "Sub-flow#1"))
                            .recipientFlow(f2 -> f2
                                    .channel(c -> c.executor(taskExecutor))
                                    .transform(p -> {
                                        throw new RuntimeException("Sub-flow#2");
                                    })),
                    null,
                    s -> s.errorChannel("scatterGatherErrorChannel"));
}

@ServiceActivator(inputChannel = "scatterGatherErrorChannel")
public Message<?> processAsyncScatterError(MessagingException payload) {
    return MessageBuilder.withPayload(payload.getCause().getCause())
            .copyHeaders(payload.getFailedMessage().getHeaders())
            .build();
}

https://github.com/adnanmamajiwala/spring-integration-sample/tree/master/dsl-scatter-gather/src/main/java/com/si/dsl/scattergather

https://docs.spring.io/spring-integration/docs/5.1.x/reference/html/#scatter-gather

]]>
SPRING INTEGRATION HEADER问题http://www.aygfsteel.com/paulwong/archive/2020/10/20/435696.htmlpaulwongpaulwongTue, 20 Oct 2020 06:56:00 GMThttp://www.aygfsteel.com/paulwong/archive/2020/10/20/435696.htmlhttp://www.aygfsteel.com/paulwong/comments/435696.htmlhttp://www.aygfsteel.com/paulwong/archive/2020/10/20/435696.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435696.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435696.html
.headerFilter("Api-Key", "Content-Type", "X-Powered-By", "Content-Language", "Transfer-Encoding", "Cache-Control", "Keep-Alive", "Set-Cookie")

https://stackoverflow.com/questions/50608415/cwsia0112e-the-property-name-keep-alive-is-not-a-valid-java-identifier

]]>
Error handling in spring integration - How to get all the errors thrown in multiple threads and send them to the error-channelhttp://www.aygfsteel.com/paulwong/archive/2020/10/15/435693.htmlpaulwongpaulwongThu, 15 Oct 2020 11:21:00 GMThttp://www.aygfsteel.com/paulwong/archive/2020/10/15/435693.htmlhttp://www.aygfsteel.com/paulwong/comments/435693.htmlhttp://www.aygfsteel.com/paulwong/archive/2020/10/15/435693.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435693.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435693.html
@Bean
public IntegrationFlow provisionUserFlow() {
return
    IntegrationFlows.from("input.channel")
    .publishSubscribeChannel(Executors.newCachedThreadPool(),
        s -> s.applySequence(true)
            .subscribe(f -> f.enrichHeaders(e -> e.header(MessageHeaders.ERROR_CHANNEL, "errorChannel", true))
                .handle(provisionerA, "provision")
                .channel("aggregatorChannel")
            )
            .subscribe(f -> f.enrichHeaders(e -> e.header(MessageHeaders.ERROR_CHANNEL, "errorChannel", true))
                .handle(provisionerB, "provision")
                .channel("aggregatorChannel"))
            )
        .get();
}

@Bean
public IntegrationFlow aggregateFlow() {
    return IntegrationFlows.from("aggregatorChannel")
                    .channel( aggregatorChannel)
                    .aggregate( a -> a.processor( collect, "aggregatingMethod"))
                    .get();
}

@Transformer( inputChannel = "errorChannel", outputChannel = "aggregatorChannel")
public Message<?> errorChannelHandler(ErrorMessage errorMessage) throws RuntimeException {

    Message<?> failedMessage =  ((MessagingException) errorMessage.getPayload()).getFailedMessage();

    Exception exception = (Exception) errorMessage.getPayload();

    return  MessageBuilder.withPayload( exception.getMessage())
                                       .copyHeadersIfAbsent( failedMessage.getHeaders() )
                                       .build();
}


https://stackoverflow.com/q/46495127/11790720



]]>
SPRING INTEGRATION子FLOWhttp://www.aygfsteel.com/paulwong/archive/2020/10/15/435692.htmlpaulwongpaulwongThu, 15 Oct 2020 03:29:00 GMThttp://www.aygfsteel.com/paulwong/archive/2020/10/15/435692.htmlhttp://www.aygfsteel.com/paulwong/comments/435692.htmlhttp://www.aygfsteel.com/paulwong/archive/2020/10/15/435692.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435692.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435692.html split之后åQŒå¯ä»¥å°†message分给不同的子flow处理åQŒé…¾|®å¦‚下:
@Bean
public IntegrationFlow parallelSplitRouteAggregateFlow() {
    return IntegrationFlows
            .from(Http.inboundGateway("/trigger"))
            .handle((p, h) -> Arrays.asList(1, 2, 3))
            .split()
            .channel(MessageChannels.executor(Executors.newCachedThreadPool()))
            .<Integer, Boolean>route(o -> o % 2 == 0, m -> m
                    .subFlowMapping(true, sf -> sf.gateway(oddFlow()))
                    .subFlowMapping(false, sf -> sf.gateway(evenFlow())))
            .aggregate()
            .get();
}

@Bean
public IntegrationFlow oddFlow() {
    return flow -> flow.<Integer>handle((payload, headers) -> "odd");
}

@Bean
public IntegrationFlow evenFlow() {
    return flow -> flow.<Integer>handle((payload, headers) -> "even");
}


https://stackoverflow.com/questions/50121384/spring-integration-parallel-split-route-aggregate-flow-fails-due-to-one-way-mess

]]>
SPRING INTEGRATION ERROR HANDLINGhttp://www.aygfsteel.com/paulwong/archive/2020/01/10/435027.htmlpaulwongpaulwongFri, 10 Jan 2020 07:32:00 GMThttp://www.aygfsteel.com/paulwong/archive/2020/01/10/435027.htmlhttp://www.aygfsteel.com/paulwong/comments/435027.htmlhttp://www.aygfsteel.com/paulwong/archive/2020/01/10/435027.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435027.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435027.htmlhttps://github.com/zakyalvan/spring-integration-java-dsl-learn

package com.jwebs.learn.errorhandling;

import java.util.Random;

import javax.jms.ConnectionFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.channel.PublishSubscribeChannel;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.dsl.core.Pollers;
import org.springframework.integration.dsl.jms.Jms;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessagingException;

/**
 * Show how to handle error in spring integration flow.
 * Please note, errorChannel in spring integration only applicable to
 * error thrown in asynch component.
 * 
 * 
@author zakyalvan
 
*/
@SpringBootApplication
@IntegrationComponentScan
public class ErrorHandlingApplication {
    public static void main(String[] args) throws Exception {
        ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder(ErrorHandlingApplication.class)
                .web(false)
                .run(args);
        
        Runtime.getRuntime().addShutdownHook(new Thread(() -> applicationContext.close()));
        
        System.out.println("Pres enter key to exit");
        System.in.read();
        System.exit(0);
    }

    @Autowired
    private ConnectionFactory connectionFactory;
    
    @Bean
    public MessageSource<Integer> randomIntegerMessageSource() {
        return () -> MessageBuilder.withPayload(new Random().nextInt()).build();
    }
    
    @Bean
    public IntegrationFlow withErrorFlow() {
        return IntegrationFlows.from(randomIntegerMessageSource(), spec -> spec.poller(Pollers.fixedDelay(1000)))
                    .handle(Jms.outboundGateway(connectionFactory)
                    .requestDestination("processor.input")
                    .replyContainer(spec -> spec.sessionTransacted(true)))
                    .get();
    }
    
    @Autowired
    @Qualifier("errorChannel")
    private PublishSubscribeChannel errorChannel;
    
    @Bean
    public IntegrationFlow errorHandlingFlow() {
        return IntegrationFlows.from(errorChannel)
                .handle(message -> System.out.println("@@@@@@@@@@@@@@@@@@@@@" + ((MessagingException) message.getPayload()).getFailedMessage().getPayload()))
                .get();
    }
}


]]>
EIP in SPRING INTEGRATIONhttp://www.aygfsteel.com/paulwong/archive/2019/10/25/434882.htmlpaulwongpaulwongFri, 25 Oct 2019 03:03:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/10/25/434882.htmlhttp://www.aygfsteel.com/paulwong/comments/434882.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/10/25/434882.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/434882.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/434882.html
  • idempotent receiver
òq‚等型,同一个MESSAGEåQŒå¦‚MESSAGE IDéƒ½ä¸€æ øP¼Œåœ¨MESSAGING¾pȝ»Ÿä¸­ä¸½Ž¡è¿è¡Œå¤šž®‘次åQŒç»“æžœéƒ½ä¸€æ øP¼Œä¸ºå•¥åQŸå› ä¸ºé‡å¤çš„MESSAGEåQŒéƒ½è¢«å¿½ç•¥äº†ã€?br /> æ–ÒŽ¡ˆåQ?br /> 消息被处理后åQŒä»Žæ¶ˆæ¯ä¸­å–出IDåQŒæ”¾å…¥META-DATA-STORE中,后箋处理消息æ—Óž¼Œè¦ä»ŽMETA-DATA-STORE中检查是否有倹{€?br />
下面˜q™ä¸ªæ–ÒŽ¡ˆåQŒID的存储和判断是否重复消息都在一个INTERCEPTOR中搞定ã€?br /> https://stackoverflow.com/questions/50401460/spring-integration-dsl-configure-idempotent-receiver-to-identify-duplicates
https://www.javacodegeeks.com/2015/09/monitoring-and-management.html


claim-check
ž®†MESSAGEçš„PAYLOAD存在STORE中,˜q”回一个IDåQŒè¿™ä¸ªID即claim-checkåQŒå¦‚果需要取MESSAGEçš„DETAIlæ—Óž¼Œå¯ä»ŽSTORE中取出MESSAGEã€?br />https://github.com/spring-projects/spring-integration/blob/master/src/reference/asciidoc/claim-check.adoc




]]>
SPRING INTEGRATION LESSONShttp://www.aygfsteel.com/paulwong/archive/2019/10/25/434881.htmlpaulwongpaulwongFri, 25 Oct 2019 01:45:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/10/25/434881.htmlhttp://www.aygfsteel.com/paulwong/comments/434881.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/10/25/434881.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/434881.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/434881.htmlLessons

Introduction to Enterprise Application Integration

In our first lesson, you will get introduced to the concepts of Enterprise Application Integration. You will learn about the and Enterprise integration patterns that can be applied to simplify integration between different platforms and the Integration strategies that can be followed for this purpose. Finally, we will discuss how and why to implement a Message driven architecture and how to achieve both Synchronous and asynchronous communication among nodes.

Spring Integration Fundamentals

In this lesson, you will get to understand how Spring Integration works under the hood. The core concepts of Spring Integration messaging system (like message channels and endpoints) will be introduced. Additionally, the components that build the framework will be discussed, including the channel adapters, transformers, filters, routers etc. Finally, the two distinct methods of communication (synchronous and asynchronous) are explained and the lesson ends with a discussion on error handling.

Spring Integration and Web Services

In this lesson, we will focus on the integration with external web services. Spring Integration comes with the necessary functionality (adapters, channels etc.) to support web services out of the box. A full example is built from scratch in order to better understand the topic.

Enterprise Messaging

In this lesson, we will focus on integrating our application with JMS messaging. For this purpose, we will use Active MQ, which will be our broker. We will show examples of sending and receiving JMS messages by using the Spring Integration JMS channel adapters. Following these examples, we will see some ways of customizing these invocations by configuring message conversion and destination resolution.

Spring Integration Full Example

In this lesson, we will wrap everything up by providing a complete application that uses several of the components provided by Spring Integration in order to provide a service to its users. We will discuss the system architecture, the actual implementation and the relevant error handling.

Monitoring and Management

In this lesson, we will examine different mechanisms of monitoring or gathering more information about what is going on within the messaging system. Some of these mechanisms consist of managing or monitoring the application through MBeans, which are part of the JMX specification. Another mechanism discussed in this chapter is how we will implement the EIP idempotent receiver pattern using a metadata store. Finally, the last mechanism described is the control bus. This will let us send messages that will invoke operations on components in the application context.



]]>
SPRING INTEGRATION DSL DEMOhttp://www.aygfsteel.com/paulwong/archive/2019/10/23/434878.htmlpaulwongpaulwongWed, 23 Oct 2019 03:55:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/10/23/434878.htmlhttp://www.aygfsteel.com/paulwong/comments/434878.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/10/23/434878.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/434878.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/434878.htmlhttps://github.com/spring-projects/spring-integration/tree/master/src/reference/asciidoc

]]>
Spring Integration 中文手册 - GOODhttp://www.aygfsteel.com/paulwong/archive/2019/10/11/434799.htmlpaulwongpaulwongFri, 11 Oct 2019 02:28:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/10/11/434799.htmlhttp://www.aygfsteel.com/paulwong/comments/434799.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/10/11/434799.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/434799.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/434799.htmlSpring Integration 中文手册 (1)


Spring Integration 中文手册 (2)

]]>
在SPRING INTEGRATION中手动开始和停止JMS LISTENERhttp://www.aygfsteel.com/paulwong/archive/2019/10/09/434781.htmlpaulwongpaulwongWed, 09 Oct 2019 09:16:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/10/09/434781.htmlhttp://www.aygfsteel.com/paulwong/comments/434781.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/10/09/434781.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/434781.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/434781.html
SPRING INTEGRATION是实çŽîCº†EIP模式的一¿Uæ¡†æžÓž¼Œå³ä‹É用CHANNELå’ŒJMS-INBOUND-ADAPTER、JMS-OUTBOUND-ADAPTERåQŒå®Œå…¨è„±¼›ÖMº†JmsTemplateçš„APIã€?br />
如果需要实现这¿Uåœºæ™¯ï¼šä»ŽBROKER取一条消息,处理消息åQŒä¸”处理途中不要再从BROKER再取消息åQŒå¤„理完后再取消息,再处理ã€?br />
˜q™æ ·è¦æ±‚手动开始和停止JMS LISTENERåQŒå³æ‰‹åŠ¨å¼€å§‹å’Œåœæ­¢JMS-INBOUND-ADAPTER、JMS-OUTBOUND-ADAPTERã€?br />
@Bean
@InboundChannelAdapter(value = "loaderResponseChannel")
public MessageSource loaderResponseSource() throws Exception {
    return Jms
            .inboundAdapter(oracleConnectionFactory())
            .configureJmsTemplate(
                    t -> t.deliveryPersistent(true)
                            .jmsMessageConverter(jacksonJmsMessageConverter())
            ).destination(jmsInbound).get();
}

当ä‹É用@InboundChannelAdapteræ—Óž¼Œä¼šè‡ªåŠ¨æ³¨å†Œä¸€ä¸ªSourcePollingChannelAdapter åQŒä½†˜q™ä¸ªåå­—比较长:configrationName.loaderResponseSource.inboundChannelAdapterã€?br />
呼叫˜q™ä¸ªå®žä¾‹çš„start()å’Œstop()æ–ÒŽ³•卛_¯ã€?br />
@Bean
public IntegrationFlow controlBusFlow() {
    return IntegrationFlows.from("controlBus")
              .controlBus()
              .get();
}

Message operation = MessageBuilder.withPayload("@configrationName.loaderResponseSource.inboundChannelAdapter.start()").build();
operationChannel.send(operation)

https://stackoverflow.com/questions/45632469/shutdown-spring-integration-with-jms-inboundadapter

https://docs.spring.io/spring-integration/docs/5.0.7.RELEASE/reference/html/system-management-chapter.html#control-bus

https://github.com/spring-projects/spring-integration-java-dsl/blob/master/src/test/java/org/springframework/integration/dsl/test/jms/JmsTests.java

https://stackoverflow.com/questions/50428552/how-to-stop-or-suspend-polling-after-batch-job-fail


]]>
Enterprise Integration Patternshttp://www.aygfsteel.com/paulwong/archive/2019/07/18/434231.htmlpaulwongpaulwongThu, 18 Jul 2019 06:11:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/07/18/434231.htmlhttp://www.aygfsteel.com/paulwong/comments/434231.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/07/18/434231.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/434231.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/434231.htmlWhy Enterprise Integration Patterns?

Enterprise integration is too complex to be solved with a simple 'cookbook' approach. Instead, patterns can provide guidance by documenting the kind of experience that usually lives only in architects' heads: they are accepted solutions to recurring problems within a given context. Patterns are abstract enough to apply to most integration technologies, but specific enough to provide hands-on guidance to designers and architects. Patterns also provide a vocabulary for developers to efficiently describe their solution.

Patterns are not 'invented'; they are harvested from repeated use in practice. If you have built integration solutions, it is likely that you have used some of these patterns, maybe in slight variations and maybe calling them by a different name. The purpose of this site is not to "invent" new approaches, but to present a coherent collection of relevant and proven patterns, which in total form an integration pattern language.

Despite the 700+ pages, our book covers only a fraction of patterns (and the problems to be solved) in the integration space. The current patterns focus on Messaging, which forms the basis of most other integration patterns. We have started to harvest more patterns but are realizing (once again) how much work documenting these patterns really is. So please stay tuned.

Messaging Patterns

We have documented 65 messaging patterns, organized as follows:



https://www.enterpriseintegrationpatterns.com/patterns/messaging/index.html

]]>
SPRING BATCH & SPRING INTEGRATION TUTORIALhttp://www.aygfsteel.com/paulwong/archive/2019/07/18/434230.htmlpaulwongpaulwongThu, 18 Jul 2019 05:21:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/07/18/434230.htmlhttp://www.aygfsteel.com/paulwong/comments/434230.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/07/18/434230.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/434230.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/434230.html

Spring JMS Artemis Example 6 minute read

A detailed step-by-step tutorial on how to connect to Apache ActiveMQ Artemis using Spring JMS and Spring Boot.

Spring JMS Topic Example 5 minute read

A detailed step-by-step tutorial on how to publish/subscribe to a JMS topic using Spring JMS and Spring Boot.

Spring JMS Integration Example12 minute read

A detailed step-by-step tutorial on how to connect to an ActiveMQ JMS broker using Spring Integration and Spring Boot.

Spring JMS Listener Example 7 minute read

A detailed step-by-step tutorial on how a Spring JMS listener works in combination with Spring Boot.

Spring JMS JmsTemplate Example 7 minute read

A detailed step-by-step tutorial on how to use JmsTemplate in combination with Spring JMS and Spring Boot.

Spring JMS Message Converter Example5 minute read

A detailed step-by-step tutorial on how to implement a message converter using Spring JMS and Spring Boot.

Spring Batch Admin Example 11 minute read

A detailed step-by-step tutorial on how to use a Spring Boot admin UI to manage Spring Batch jobs.

Spring Batch Example 11 minute read

A detailed step-by-step tutorial on how to implement a Hello World Spring Batch job using Spring Boot.



]]>
Spring Integration Java DSLhttp://www.aygfsteel.com/paulwong/archive/2019/07/18/434229.htmlpaulwongpaulwongThu, 18 Jul 2019 05:16:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/07/18/434229.htmlhttp://www.aygfsteel.com/paulwong/comments/434229.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/07/18/434229.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/434229.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/434229.htmlThis time I decided to play a little bit with Spring Integration Java DSL. Which has been merged directly into Spring Integration Core 5.0, which is smart and obvious move because:

  • Everyone starting the new Spring projects based on Java Config uses that
  • SI Java DSL enables you to use new powerfull Java 8 features like Lambdas
  • You can build your flow using the Builder pattern based on IntegrationFlowBuilder

Let's take a look on the samples howto use that based on ActiveMQ JMS.


https://bitbucket.org/tomask79/spring-integration-java-dsl/src/master/



]]>
Message Processing With Spring Integrationhttp://www.aygfsteel.com/paulwong/archive/2019/06/05/433840.htmlpaulwongpaulwongWed, 05 Jun 2019 03:08:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/06/05/433840.htmlhttp://www.aygfsteel.com/paulwong/comments/433840.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/06/05/433840.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/433840.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/433840.html
https://dzone.com/articles/message-processing-spring



]]>
Spring integration 基本概念http://www.aygfsteel.com/paulwong/archive/2019/06/05/433839.htmlpaulwongpaulwongWed, 05 Jun 2019 02:36:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/06/05/433839.htmlhttp://www.aygfsteel.com/paulwong/comments/433839.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/06/05/433839.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/433839.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/433839.html

1.spring integration 's architecture

主要提供两个功能åQ?/p>

在系¾lŸå†…提供实现轻量¾U§ã€äº‹ä»‰™©±åŠ¨äº¤äº’è¡Œä¸ºçš„æ¡†æž¶

在系¾lŸé—´æä¾›ä¸€¿UåŸºäºŽé€‚配器的òq›_°åQŒä»¥æ”¯æŒç‰|´»çš„ç³»¾lŸé—´äº¤äº’

2.spring integration对于企业集成模式的支�/p>

2.1MessageåQšä¸€ä¸ªä¿¡æ¯çš„单元åQŒé€šå¸¸æœ‰æ¶ˆæ¯å¤´åQˆheaderåQ‰å’Œæ¶ˆæ¯å†…容åQˆpayloadåQ‰ç»„æˆ?/p>

2.2Message channelåQšæ¶ˆæ¯å¤„ç†èŠ‚ç‚¹ä¹‹é—´çš„˜qžæŽ¥åQŒè´Ÿè´£å°†Message从生产者传输到消费者ã€?/p>

    æ ÒŽ®æ¶ˆè´¹è€…的多少åQŒå¯åˆ†äØ“point to pointå’Œpublish-subscribe两种


    æ ÒŽ®æ¶ˆæ¯ä¼ è¾“æ–¹å¼çš„ä¸åŒï¼Œåˆ†äØ“åŒæ­¥å’Œå¼‚æ­¥ä¸¤¿U?/p>

2.3Message EndpointåQšæ¶ˆæ¯å¤„ç†èŠ‚ç‚¹ï¼Œæ¶ˆæ¯ä»ŽèŠ‚ç‚¹è¿›å…¥é€šé“åQŒä¹Ÿæ˜¯ä»ŽèŠ‚ç‚¹¼›Õd¼€é€šé“

几个常见的Message EndPointåQ?/p>

CHANNEL ADAPTERåQŒç”¨äºŽè¿žæŽ¥è¯¥é€‚配器的特点是单向消息流的,要么是消息通过该适配器进入通道åQŒè¦ä¹ˆæ˜¯æ¶ˆæ¯é€šè¿‡è¯¥é€‚配器离开通道


MESSAGING GATEWAYåQŒå¤„理的消息‹¹å’ŒChannel Adapter不同åQŒä¸æ˜¯å•向的åQŒå³æœ‰è¿›å…¥è¯¥èŠ‚ç‚¹çš„æ¶ˆæ¯ï¼Œä¹Ÿä¼šä»Žè¯¥èŠ‚ç‚¹å‘å‡ºæ¶ˆæ¯ã€?br />



SERVICE ACTIVATORåQŒè¯¥èŠ‚ç‚¹è°ƒç”¨æœåŠ¡æ¥å¤„ç†è¾“å…¥çš„æ¶ˆæ¯åQŒåƈž®†æœåŠ¡è¿”å›žçš„æ•°æ®å‘é€åˆ°è¾“å‡ºé€šé“ã€‚åœ¨spring integration中,调用的方法被限定为本地方法调用ã€?br />


ROUTERåQŒèµ\由器åQŒå°†è¾“入的消息èµ\由到某个输出通道ä¸?/p>


SPLITTERåQŒå°†è¾“入的消息拆分成子消æ?br />


AGGREGATORåQŒå°†è¾“入的多个消息合òq¶äؓ一个消æ?br />


3.观看书中例子hello-world思�/p>

‹¹‹è¯•gatewayæ—Óž¼Œä¸‹é¢ä»£ç å‘通道names内放入消息worldåQ?/p>


然后service-activator从names通道中获得消息worldåQŒè°ƒç”¨æ–¹æ³•sayHello˜q”回值到¾l™gatewayåQ?/p>

解释åQšgateway有一个serviceåQinterface的属性,˜q™ä¸ªå±žæ€§æŒ‡å‘一个interface。当我们用一个接口声明一个gatewayæ—Óž¼Œspring integration会自动帮我们生成该接口的代理¾c»ï¼Œ˜q™æ ·å½“我们往gateway发送消息时åQŒspring integration会通过代理¾cÀLŠŠæ¶ˆæ¯è½¬å‘åˆ°defaultåQrequeståQchannel中去



作者:马国æ ?br /> 链接åQšhttps://www.jianshu.com/p/bf1643539f99
来源åQšç®€ä¹?br /> ½Ž€ä¹¦è‘—作权归作者所有,ä»ÖM½•形式的è{载都误‚”¾pÖM½œè€…èŽ·å¾—æŽˆæƒåÆˆæ³¨æ˜Žå‡ºå¤„ã€?/div>

]]>
如何在SPRING INTEGRATION中ä‹É用事åŠ?/title><link>http://www.aygfsteel.com/paulwong/archive/2019/06/04/433836.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Tue, 04 Jun 2019 06:19:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2019/06/04/433836.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/433836.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2019/06/04/433836.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/433836.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/433836.html</trackback:ping><description><![CDATA[<div>File Polling using the Spring Integration DSL</div> <a target="_blank">http://porterhead.blogspot.com/2016/07/file-polling-using-spring-integration.html</a> <br /><a target="_blank"><br />https://github.com/iainporter/spring-file-poller</a><br /><br /><br />Transaction Support in Spring Integration<br /><a target="_blank">https://www.baeldung.com/spring-integration-transaction</a><img src ="http://www.aygfsteel.com/paulwong/aggbug/433836.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2019-06-04 14:19 <a href="http://www.aygfsteel.com/paulwong/archive/2019/06/04/433836.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用JAMES实现自己的邮件服务器http://www.aygfsteel.com/paulwong/archive/2012/12/16/393057.htmlpaulwongpaulwongSun, 16 Dec 2012 05:14:00 GMThttp://www.aygfsteel.com/paulwong/archive/2012/12/16/393057.htmlhttp://www.aygfsteel.com/paulwong/comments/393057.htmlhttp://www.aygfsteel.com/paulwong/archive/2012/12/16/393057.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/393057.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/393057.html ½Ž€ä»?br /> James 是一个企业çñ”的邮件服务器åQŒå®ƒå®Œå…¨å®žçŽ°äº†smtp å’?pops 以及nntp 协议。同æ—Óž¼Œjames服务器又是一个邮件应用程序åã^台。James的核心是Mailet API,而james 服务齐是一个mailet的容器。它可以让你非常å®ÒŽ˜“的实现出很强大的邮äšg应用½E‹åºã€‚James开源项目被òq¿æ³›çš„应用于与邮件有关的™å¹ç›®ä¸­ã€‚你可以通过它来搭徏自己的邮件服务器。我们可以利用Mailet API,¾~–程接口来实现自己所需的业务。James集成了Avalon 应用½E‹åºæ¡†æž¶ä»¥åŠPhoenix Avalon 框架容器。Phoenix为james 服务器提供了强大的支持。需要说明的是Avalon开源项目目前已¾lå…³é—­ã€?br /> 快速上æ‰?br /> 安装james
我这‹Æ¡ä‹É用的安装包是james 2.3.1。大家可以从˜q™é‡Œä¸‹è²åˆ°http://james.apache.org/download.cgi
现在让我们开始我们激动äh心的james之旅。首先我们将james-binary-2.3.1.zip解压¾~©ä¸‹è½½åˆ°ä½ çš„安装目录。我们可以把˜q™ä¸ª˜q‡ç¨‹ç†è§£ä¸ºå®‰è£…çš„˜q‡ç¨‹ã€‚我在这里将它解压到c:\.òq¶ä¸”把它改名为james.˜q™æ ·æˆ‘们的jamesž®±å®‰è£…å¥½äº†ã€‚ç›®å½•äØ“C:\james。很½Ž€å•吧åQ?br />
准备知识 åQ?学习一些必要的知识
在我使用james的时候让我感觉首先理解james的应用程序结构是很重要的。否则你会在使用中感到很困惑ã€?br /> 它的应用½E‹åº¾l“构是这æ ïLš„åQ?br /> James
|_ _apps
|_ _bin
|_ _conf
|_ _ext
|_ _lib
|_ _logs
|_ _tools
我们重点介绍一下两个文件夹bin �apps.
bin目录中的run.batå’Œrun.sh是James的启动程序。只要记住这个重要文件就可以ã€?br /> 启动之后控制台显½Cºå¦‚下:
Using PHOENIX_HOME: C:\james
Using PHOENIX_TMPDIR: C:\james\temp
Using JAVA_HOME: C:\j2sdk1.4.2_02
Phoenix 4.2
James Mail Server 2.3.1
Remote Manager Service started plain:4555
POP3 Service started plain:110
SMTP Service started plain:25
NNTP Service started plain:119
FetchMail Disabled
Apps 目录下有个james的子目录˜q™ä¸ªç›®å½•是它的核心ã€?br /> james
|_ _SAR-INF
|_ _conf
|_ _logs
|_ _var
|_mail
|_address-error
|_error
|_indexes
|_outgoing
|_relay-denied
|_spam
|_spool
|_nntp
|_....

|_users
SAR-INF 下有一个config.xml是james中的核心配置文äšgã€?br /> Logs 包含了与james有关的Log。调试全靠它了ã€?br /> Var 包含了一些文件夹通过它们的名字我们大概也能猜‹¹‹å‡ºå®ƒä»¬çš„用途。Mail主要用于存储邮äšg。nntp主要用于新闻服务器。Users用于存储所有邮件服务器的用戗÷€‚也ž®±æ˜¯é‚®äšg地址前面的东东。如åQšpig@sina.comçš„pigž®±æ˜¯æ‰€è°“用用户ã€?br />
创徏用户åQ?br /> 我们在James上徏若干用户åQŒç”¨æ¥æµ‹è¯•收发邮件。当然如果你不用james本èín的用户也可以。James以telnet 的方式提供了接口用来æ·ÕdŠ ç”¨æˆ·ã€‚ä¸‹é¢æˆ‘æ¥æ¼”½CÞZ¸€ä¸‹ã€?br /> 首先使用telnet来连接jamesçš„remote manager .
1.telnet localhost 4555 回èžR
2.然后输入½Ž¡ç†å‘˜ç”¨æˆ·åå’Œå¯†ç ï¼ˆuser/pwd åQ?root/root 是默认设¾|®è¿™ä¸ªå¯ä»¥åœ¨config.xml中修改)
JAMES Remote Administration Tool 2.3.1
Please enter your login and password
Login id:
root
Password:
root
Welcome root. HELP for a list of commands

3.æ·ÕdŠ ç”¨æˆ·
adduser kakaxi kakaxi
User kakaxi added

Adduser mingren mingren
User mingren added

4.查看æ·ÕdŠ æƒ…å†µ
listusers
Existing accounts 2
user: mingren
user: kakaxi
得到上面的信息说明我们已¾læ·»åŠ æˆåŠŸã€?br />

发送器
˜q™ä¸ª¾cÖM¸»è¦ç”¨æ¥æµ‹è¯•我们的邮äšg服务器,可以不用ž®†å…¶æ‰“入包中ã€?br /> java 代码 
package com.paul.jamesstudy;   
  
import java.util.Date;   
import java.util.Properties;   
  
import javax.mail.Authenticator;   
import javax.mail.Message;   
import javax.mail.PasswordAuthentication;   
import javax.mail.Session;   
import javax.mail.Transport;   
import javax.mail.internet.InternetAddress;   
import javax.mail.internet.MimeMessage;   
  
public class Mail {   
    private String mailServer, From, To, mailSubject, MailContent;   
  
    private String username, password;   
  
    private Session mailSession;   
  
    private Properties prop;   
  
    private Message message;   
  
    // Authenticator auth;//认证   
    public Mail() {   
        // è®„¡½®é‚®äšg相关   
        username = "kakaxi";   
        password = "kakaxi";   
        mailServer = "localhost";   
        From = "kakaxi@localhost";   
        To = "mingren@localhost";   
        mailSubject = "Hello Scientist";   
        MailContent = "How are you today!";   
    }   
    public void send(){   
        EmailAuthenticator mailauth =    
new EmailAuthenticator(username, password);   
        // è®„¡½®é‚®äšg服务å™?nbsp;  
        prop = System.getProperties();   
        prop.put("mail.smtp.auth", "true");   
        prop.put("mail.smtp.host", mailServer);   
        // äº§ç”Ÿæ–°çš„Session服务   
        mailSession = mailSession.getDefaultInstance(prop,   
                (Authenticator) mailauth);   
        message = new MimeMessage(mailSession);   
  
        try {   
        message.setFrom(new InternetAddress(From)); // è®„¡½®å‘äšgäº?nbsp;  
        message.setRecipient(Message.RecipientType.TO,    
new InternetAddress(To));// è®„¡½®æ”¶äšgäº?nbsp;  
        message.setSubject(mailSubject);// è®„¡½®ä¸»é¢˜   
        message.setContent(MailContent, "text/plain");// è®„¡½®å†…容   
        message.setSentDate(new Date());// è®„¡½®æ—¥æœŸ   
        Transport tran = mailSession.getTransport("smtp");   
        tran.connect(mailServer, username, password);   
        tran.send(message, message.getAllRecipients());   
        tran.close();   
        } catch (Exception e) {   
            e.printStackTrace();   
        }   
    }   
    public static void main(String[] args) {   
        Mail mail;   
        mail = new Mail();   
        System.out.println("sending");   
        mail.send();   
        System.out.println("finished!");   
    }   
  
}   
  
class EmailAuthenticator extends Authenticator {   
    private String m_username = null;   
  
    private String m_userpass = null;   
  
    void setUsername(String username) {   
        m_username = username;   
    }   
  
    void setUserpass(String userpass) {   
        m_userpass = userpass;   
    }   
  
    public EmailAuthenticator(String username, String userpass) {   
        super();   
        setUsername(username);   
        setUserpass(userpass);   
    }   
  
    public PasswordAuthentication getPasswordAuthentication() {   
        return new PasswordAuthentication(m_username, m_userpass);   
    }   
}   




]]>
SRING INTEGRATION + BATCHhttp://www.aygfsteel.com/paulwong/archive/2012/10/21/389968.htmlpaulwongpaulwongSun, 21 Oct 2012 09:23:00 GMThttp://www.aygfsteel.com/paulwong/archive/2012/10/21/389968.htmlhttp://www.aygfsteel.com/paulwong/comments/389968.htmlhttp://www.aygfsteel.com/paulwong/archive/2012/10/21/389968.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/389968.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/389968.html阅读全文

]]>
spring integration同步数据库数æ?/title><link>http://www.aygfsteel.com/paulwong/archive/2012/10/17/389716.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 17 Oct 2012 03:50:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2012/10/17/389716.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/389716.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2012/10/17/389716.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/389716.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/389716.html</trackback:ping><description><![CDATA[     摘要: éœ€æ±‚äØ“åQšå½“客户已有¾pȝ»Ÿçš„æ•°æ®è¢«åŒæ­¥åˆ°æˆ‘æ–ÒŽ•°æ®åº“后,若再有新数据åQŒåªåŒæ­¥æ–°æ•°æ®åˆ°æˆ‘方数据库。解冻I¼šå› äؓ客户的业务表是不能变动的åQŒæˆ‘方在客户数据库中新徏一状态表åQŒè®°å½•哪些数据被更新˜q‡ã€‚当客户业务表有新数据插入时åQŒç”¨è§¦å‘器将新数据idæ’å…¥åˆ°çŠ¶æ€è¡¨ã€‚äØ“æ–¹ä¾¿å®žä¾‹åQšä¸šåŠ¡è¡¨ppåQŒçŠ¶æ€è¡¨status¾l“构为:ppåQ? Code highlighting produced by Actipro CodeHighli...  <a href='http://www.aygfsteel.com/paulwong/archive/2012/10/17/389716.html'>阅读全文</a><img src ="http://www.aygfsteel.com/paulwong/aggbug/389716.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2012-10-17 11:50 <a href="http://www.aygfsteel.com/paulwong/archive/2012/10/17/389716.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SPRING INTEGRATION + SPRING BATCHhttp://www.aygfsteel.com/paulwong/archive/2012/10/16/389625.htmlpaulwongpaulwongMon, 15 Oct 2012 16:11:00 GMThttp://www.aygfsteel.com/paulwong/archive/2012/10/16/389625.htmlhttp://www.aygfsteel.com/paulwong/comments/389625.htmlhttp://www.aygfsteel.com/paulwong/archive/2012/10/16/389625.html#Feedback7http://www.aygfsteel.com/paulwong/comments/commentRss/389625.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/389625.html阅读全文

]]>
SPRING INTERGRATION资源http://www.aygfsteel.com/paulwong/archive/2012/06/11/380483.htmlpaulwongpaulwongMon, 11 Jun 2012 02:07:00 GMThttp://www.aygfsteel.com/paulwong/archive/2012/06/11/380483.htmlhttp://www.aygfsteel.com/paulwong/comments/380483.htmlhttp://www.aygfsteel.com/paulwong/archive/2012/06/11/380483.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/380483.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/380483.html http://wangleifire.iteye.com/blog/351749



]]>
SPRING INTERGRATIONhttp://www.aygfsteel.com/paulwong/archive/2012/06/11/380482.htmlpaulwongpaulwongMon, 11 Jun 2012 02:04:00 GMThttp://www.aygfsteel.com/paulwong/archive/2012/06/11/380482.htmlhttp://www.aygfsteel.com/paulwong/comments/380482.htmlhttp://www.aygfsteel.com/paulwong/archive/2012/06/11/380482.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/380482.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/380482.htmlž®†å¤„理业务的‹¹ç¨‹æ‹†åˆ†æˆä¸€ä¸ªä¸€ä¸ªé“¾åQŒå‰é¢å¤„理完åQŒå†‹z„¡»™ä¸‹ä¸€ä¸ªï¼Œ¾cÖM¼¼HTTP中的FILTER
不用安装服务器,内嵌在SPRING容器中,对外支持多种格式的数据,外部¾pȝ»Ÿå¦‚要和SPRING INTERGRATION整合åQŒä¸éœ€è¦å†˜q›è¡Œå¼€å?br />处理‹¹ç¨‹ä¸€èˆ¬å°±æ˜¯ï¼ŒADAPTER去读取外部数据,转换后放到CHANNEL中,ENDPOINT处理CHANNEL中的数据åQŒå§”‹z„¡»™ä¸‹ä¸€ä¸ªCHANNELåQŒä¸‹ä¸€ä¸ªENDPOINT处理åQŒé€šè¿‡ADAPTER写到外部接口中ã€?br />
  1. ADAPTER
    外部¾pȝ»Ÿä¸ŽCHANNEL之间的桥梁,获取外部数据ž®†å…¶æ”‘Öˆ°CHANNEL去,有FTPåQŒJMSåQŒæ–‡ä»¶ç³»¾lŸçš„

  2. CHANNEL
    里面放MESSAGE对象åQŒMESSAGE里面可以放自定义对象åQŒä»¥æä¾›æ¶ˆè´¹è€…ä‹Éç”?br />
  3. ENDPOINT
    CHANNEL的消费者,CHANNEL与ENDPOINT是一对一的关¾p»ï¼Œæ‰€ä»¥å¦‚果想在一个CHANNE下对应多个ENDPOINTåQŒæ˜¯åšä¸åˆ°çš„åQŒåªèƒ½å¢žåŠ CHANNEL

    Service ActivatorsåQšä»ŽINPUT CHANNEL中取å‡ÞZ¸€ä¸ªå¯¹è±¡ä½œä¸ºå‚敎ͼŒè°ƒç”¨è®„¡½®çš„POJO的方法,ž®†ç»“果放到OUTPUT CHANNELä¸?br />TransformersåQšå¯¹CHANNEL中的对象˜q›è¡Œ¾cÕdž‹è½¬æ¢
    军_®š‹¹å‘çš„ENDPOINTåQšRoutersåQŒSPLITER

  4. 例子
<?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"
    xmlns:stream
="http://www.springframework.org/schema/integration/stream"
    xsi:schemaLocation
="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/integration
            http://www.springframework.org/schema/integration/spring-integration.xsd
            http://www.springframework.org/schema/integration/stream
            http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd"
>

    
<gateway id="cafe" service-interface="org.springframework.integration.samples.cafe.Cafe"/>

    
<channel id="orders"/>
    
<!-- æ­¤å¤„orders里面的对象是一个一个MessageåQŒè°ƒç”¨payload则取到Order
         è°ƒç”¨items则得到OrderItem ListåQŒæ‹†åˆ†æˆOrderItemä»¥ä¸€ä¸ªäØ“å•ä½æ”‘Öˆ°
         drinksä¸?br />     
-->
    
<splitter input-channel="orders" expression="payload.items" output-channel="drinks"/>

    
<channel id="drinks"/>
    
<!-- æ­¤å¤„drinks里面的对象是一个一个OrderItemåQŒè°ƒç”¨iced则取到布ž®”å€?br />         å¦‚果是true则放到coldDrinks中,如是false则放到hotDrinksä¸?br />     -->
    
<router input-channel="drinks"  expression="payload.iced ? 'coldDrinks' : 'hotDrinks'"/>

    
<channel id="coldDrinks">
        
<queue capacity="10"/>
    
</channel>
    
<service-activator input-channel="coldDrinks" ref="barista" method="prepareColdDrink" output-channel="preparedDrinks"/>

    
<channel id="hotDrinks">
        
<queue capacity="10"/>
    
</channel>
    
<!-- ž®†è¾“入通道中的OrderItem转成Drink -->
    
<service-activator input-channel="hotDrinks" ref="barista" method="prepareHotDrink" output-channel="preparedDrinks"/>

    
<channel id="preparedDrinks"/>
    
<!-- ž®†é€šé“中的Drink按一个Order˜q›è¡Œåˆåƈ成一个List<Order>-->
    
<aggregator input-channel="preparedDrinks"  method="prepareDelivery" output-channel="deliveries">
        
<beans:bean class="org.springframework.integration.samples.cafe.xml.Waiter"/>
    
</aggregator>

    
<stream:stdout-channel-adapter id="deliveries"/>

    
<beans:bean id="barista" class="org.springframework.integration.samples.cafe.xml.Barista"/>

    
<poller id="poller" default="true" fixed-delay="1000"/>

</beans:beans>


]]>
Ö÷Õ¾Ö©Öë³ØÄ£°å£º ¯»ôÏØ| ̫ԭÊÐ| ÂêÄÉË¹ÏØ| °¢¿ËÌÕÏØ| ÀÖÖÁÏØ| ÐË»¯ÊÐ| ʯÃÅÏØ| °¢ÍßÌáÏØ| ÏĽòÏØ| ½­¿ÚÏØ| µ¤¶«ÊÐ| ÒÀÀ¼ÏØ| °²ÑôÏØ| Ó¢É½ÏØ| ÄÏ·áÏØ| Ñô¶«ÏØ| ¶¼½­ÑßÊÐ| Ê©±üÏØ| °²ÑôÏØ| ËçÀâÏØ| ³¤ÄþÇø| ºÍÌïÊÐ| ³àË®ÊÐ| ËìÏªÏØ| ÉÏÓÌÏØ| °Í³þÏØ| ¼ÎÏéÏØ| ¹²ºÍÏØ| ÁÙ¸ßÏØ| аͶû»¢×óÆì| ÅîÀ³ÊÐ| ¿üÍÍÊÐ| ½¨ÑôÊÐ| ãòË®ÏØ| Ì«ºÍÏØ| ÆëºÓÏØ| ¾ÅÕ¯¹µÏØ| ¸ÞÀ¼ÏØ| ƽºÍÏØ| ÏÉÌÒÊÐ| ºÏɽÊÐ|