1ã€ã®ãããžã§ã¯ãã®æŽå²ã
ã©ã¯ãã倢èŠãããšã¯ãããŸããïŒ ã ããç§ãããŸããã ãããã3幎ç®ãã£ã¡ã«ãšä»äºããããšããã©ã¯ãã ãã§ãªã倢ãèŠãããã«ãªããŸãã
äžè¬çã«ãç§ã¯ç§ã®çµéšãå ±æããã©ã¯ãã«ã€ããŠæžãããããã調çããæ¹æ³ãæããŸãã ããã¯3ã€ã®ããŒãã«åãããäžé£ã®èšäºã§ããæåã®ããŒãã¯ãåµé æ§ã®ç©èªãèŠçã«èå³ããã人åãã§ãã 2çªç®ã¯ãããæè¡çã§ãçµ±åãã¿ãŒã³ãšãã®ã¢ããªã±ãŒã·ã§ã³ã«ã€ããŠã3çªç®ã¯ããšã©ãŒãšãããã°ã«ã€ããŠã§ãã
ãµãŒãã¹ãçµã¿åãããå¿ èŠãããå Žåã¯ãããã§Camelã®å©ç¹ã確èªã§ããŸãã æ°ãããã®ã®äœ¿ãæ¹ãåŠã³ããå Žåã¯ãåºæ¬ããå§ããŸãããã ãã¹ãŠã®ããŒã ã«ããã¹ããŒãªãŒãšå ã®ããããæ°ã«å ¥ã£ãããèªã¿é²ããŠãã ããã
çµ±åã¿ã¹ã¯
ãµãŒãã¹ãã¹ã®å¿ èŠæ§ããå§ããŸãã ææ ã蟌ããŠã¢ã³ã¹ã¿ãŒã®ãç®ã®åŸãããšåŒã°ãã倧èŠæš¡ãªã·ã¹ãã ãéçºããŠããŸãã æªç©ã¯å€§ãããŠæãããããšãå€æããŸããããå®éã«ã¯BPMã·ã¹ãã ïŒããžãã¹ããã»ã¹ç®¡çã·ã¹ãã ïŒã®1ã€ã§ããã ãã¹ãŠã¯æ°å¹Žåã«å§ãŸããŸããã äŒè°ã§ããããžã§ã¯ããããŒãžã£ãŒã¯å°æ¥ã®èšç»ã«ã€ããŠè©±ããŸããã
-ååãè¿ãå°æ¥ãå€æ°ã®å éšããã³å€éšã·ã¹ãã ãšçµ±åããäºå®ã§ãã 次ã«ãã¢ããªã¹ããã¿ã¹ã¯ã®æºåãéå§ã§ããããã«ãäœç³»çãªã¢ãããŒããå®è¡ããå¿ èŠããããŸãã
ãããããã°ããã®éã圌ã¯ç§ãã¡ãçµ±åããªããã°ãªããªãã·ã¹ãã ã«ã€ããŠè©±ããŸããã elibrary.ruãªã©ã®å€éšã®æåãªã·ã¹ãã ãšããŸã äœæãããŠããªãå éšã®ã·ã¹ãã ã®äž¡æ¹ããããŸãã ã¹ããŒãªãŒã®æåŸã«ãããŸããŸãªã¿ã€ãã®ã·ã¹ãã ãšã®çµ±åã®ç¹åŸŽçãªæ©èœãç¹å®ãããŸããã å€éšã·ã¹ãã ã®å Žå-ããã¯ã亀æããããµããžã§ã¯ããšãªã¢ã®ããã»ã¹ãšãªããžã§ã¯ãïŒããžãã¹ãªããžã§ã¯ãïŒã®èšè¿°ã®å€§ããªäžç¢ºå®æ§ã§ãã ããããããŒã¿è»¢éã®æ¹åïŒããŒããŸãã¯ã¢ã³ããŒãïŒã¯æ確ã§ããã ããŒã¿äŒéãã£ãã«ãä¿è·ããé ä¿¡ãä¿èšŒããããã®è¿œå èŠä»¶ãããã³èª€ã£ãããŒã¿ãä¿®æ£ããããŒã«ãäœæããããã®åææ¡ä»¶ã衚瀺ãããŸããã 2çªç®ã®å éšã·ã¹ãã ã§ã¯ãããæ確ã«ãªããŸããã åã·ã¹ãã ã®æ©èœçãªç®çãæ確ã«èª¬æãããŸããã 転éãããªããžã§ã¯ãã®ãµãŒã¯ã«ãäœæããããšãã§ãããããã§ã ãããããããã®ã·ã¹ãã ã«ã€ããŠã®ã¿ãäžç¢ºå®æ§ã¯ç§ãã¡ãããã¬ãã«ã§çŸããŸãã-ããŸãããæéããããŸã-ãããå®çŸããæéããããŸããã ã¢ããªã±ãŒã·ã§ã³é åã®è©³çŽ°ã«å ¥ãããšãªããç§ãéäžããå žåçãªã¿ã¹ã¯ã«éå®ããŸãã
- æ å ±ã¯ãæšæºãããã³ã«ã䜿çšããŠã¡ã€ã³ã·ã¹ãã ã«ã¢ããããŒãããå¿ èŠããããŸãã è°è«ã®æç¹ã§ãå€éšã·ã¹ãã ã«ã€ããŠã¯HTTPãftpã å éšçšïŒJMSãHTTPãNFSãSMBãããã³/ãŸãã¯RMIã€ã³ã¿ãŒãã§ãŒã¹ã䜿çšã ãã®ã¢ãŒããã¯ãã£ã§ã¯ã©ã®ã¢ãŒããã¯ãã£ã§è§£æ±ºã§ããŸããïŒ
- ã¡ã€ã³ã·ã¹ãã ããæ å ±ãã¢ã³ããŒãããæšæºãããã³ã«ã®ããããã䜿çšããŠå€éšã·ã¹ãã ã«è»¢éããå¿ èŠããããšããŸãã ãã®ãããªåé¡ã解決ããæ¹æ³ã¯äœã§ããããïŒ
- ãŸãã¯ã1ã€ã2ã€ãnåã®ããžãã¹ãªããžã§ã¯ãã転éããå¿ èŠããããŸãã ã©ã®ããã«ããŒã¿ãæºåããã©ã®åœ¢åŒã䜿çšããã®ã§ããããïŒ
- äžæçã«å©çšã§ããªãã¡ãŒã«ãµãŒããŒãä»ããŠé»åã¡ãŒã«ã¡ãã»ãŒãžãéä¿¡ãããšããŸãã ãããè¡ãã«ã¯ããŠãŒã¶ãŒã¯åŸè ãå©çšå¯èœã«ãªããŸã§åŸ ã€ããçŸåšäœæ¥ãå®äºã§ããªãããšã«é¢ããã¡ãã»ãŒãžãåä¿¡ããå¿ èŠããããŸãã é ä¿¡ãä¿èšŒãããŠãŒã¶ãŒããããã¯ããªãã·ã¹ãã ãã©ã®ããã«æ§ç¯ã§ããŸããïŒ
- æã®1æãŸãã¯3æã«å€éšã·ã¹ãã ããæ å ±ãåéããå¿ èŠããããšæ³å®ããŠããŸããããã®æç¹ã§ã·ã¹ãã ã¯ã¡ã³ããã³ã¹ã®ããã®äœæ¥ãäžæããŸããã ã¡ã€ã³ã·ã¹ãã ã䜿çšã§ããªããšãã«ããŒã¿ã®ã¢ããããŒããšããŠã³ããŒãã®ããã»ã¹ãåæ¢ããªãããšã確èªããæ¹æ³
- æåŸã®ã¿ã¹ã¯ïŒãã°ã€ã³ãšãã¹ã¯ãŒãããã°ããå€æŽããŠãå€éšã·ã¹ãã ãŸãã¯éä¿¡ãããã³ã«ã«ftpããsftpã«ã¢ã¯ã»ã¹ã§ããããã«ããå¿ èŠããããŸãã ã¡ã€ã³ã·ã¹ãã ã®åäœãäžæããã«ãæè»ã«èšå®ãå€æŽã§ããããã«ããã«ã¯ã©ãããã°ããã§ããããïŒ
ã¿ã¹ã¯ã«ã€ããŠèª¬æããåŸãã¡ã€ã³ã·ã¹ãã ãä»ã®ã·ã¹ãã ãšæ¥ç¶ããã¹ã¿ã³ãã¢ãã³ã¢ããªã±ãŒã·ã§ã³ãäœæããããšã«ããŸããã äžéãªã³ã¯ã䜿çšãããšããèãæ¹ã¯æ°ãããã®ã§ã¯ãªãã ãšã³ã¿ãŒãã©ã€ãºãµãŒãã¹ãã¹ãŸãã¯ESBãšããçšèªã§çµ±åã®äžçã§ç¥ãããŠããŸãã ã¢ããªã±ãŒã·ã§ã³ãæã€ã¹ãæ©èœã®ç¯å²ãæŠèª¬ããŸãããã ã¿ã¹ã¯ã®æèšã«åºã¥ããŸãã 次ã®ããšãã§ããå¿ èŠããããŸãã
- HTTPãFTPã JMSããŸãã¯RMIã€ã³ã¿ãŒãã§ãŒã¹ã䜿çšããæšæºãããã³ã«ã䜿çšããŠãä»ã®ã·ã¹ãã ãšå¯Ÿè©±ããŸãã
- NFSã§äœæ¥ããããã«ãããŒã«ã«ãã¡ã€ã«ã·ã¹ãã ã§ãã¡ã€ã«ãèªã¿åããæžã蟌ã¿ãäœæãã
- SMTPãµãŒããŒãä»ããŠã¡ãŒã«ã¡ãã»ãŒãžãéä¿¡ããŸãã
- ãã©ã³ã¹ããŒããã©ãŒãããXMLãJSONã®ããããã解æããŸã
- æè»ãªèšå®ããããŸã
- Javaããã°ã©ãã³ã°èšèªã®1ã€ã§ããGroovyã§ãã©ãŒãããæ¿èªã«ãŒã«ãèšè¿°ããããšãã§ããŸãã ãããã®èšèªã§äœæ¥ãããããåŠç¿ã®ããã®è¿œå ã®ãªãŒããŒãããããªãããšãæåŸ ã§ããŸããã
- XSLTãšxPathãæäœããæ©èœããã©ã¹ã«ãªããŸãã
æšè«ããå®è·µãž
ãã°ããããŠãæ€çŽ¢ããã»ã¹ãå¢ããå¢ãå§ãããšããã¢ããªã¹ãã¯ã¯ã©ã€ã¢ã³ãã«æåã®ã¹ããŒãã¡ã³ããæžãããäŸé ŒããŸããã
-ã¿ããªãããã§ãããã¯ã·ã§ã³ãæžããã®ã§ãããã«ããå¿ èŠããããŸãã 顧客ã¯æšæ¥åœŒå¥³ãåŸ ã£ãŠããã®ã§ãè©ŠããŠã¿ãŠãã ããã
ããã¯ãã°ãã°èµ·ãããŸãããç§ãã¡ã¯åžžã«æ°ããæ©èœãæéå ã«äœæããããšãã§ããŸãã ä»åãäŸå€ã§ã¯ãªãã倧éã®äœæ¥ãšå®è£ ã®å³ããç· ãåããåŸ ã£ãŠããŸããã ãã®å®åŒåã«ã¯ãµãŒãã¹ãã¹ã䜿çšã§ããŸããã§ãããããããã¿ã€ããäœæããæåã®å®çšçãªã¿ã¹ã¯ãšããŠå®åŒåã䜿çšããŸããã
ãããŸã§ã®éããããã¿ã€ããæ§ç¯ãããã¯ãããžãŒãéžæããå¿ èŠããããŸããã èªè»¢è»ãåçºæããŠãŒãããå§ããã®ã¯çŽ æŽãããããšã§ãããè²»çšãããããããŸãã çµæãããã«å¿ èŠã ã£ããããç¬èªã®ãœãªã¥ãŒã·ã§ã³ã䜿çšãããŸããã§ãããã財åäžã®åé¡ã調æŽããŠè§£æ±ºããã«ã¯æéãããããŸãã ãããã£ãŠã圌ãã¯ãªãŒãã³ãœãŒã¹ãããžã§ã¯ãã«ç®ãåããŸããã åœæãéžæè¢ã¯éãããŠããããããã©ã¯ããã®ã¡ãªãããäžç®ã§è©äŸ¡ããããšãã§ããŸããã
å³ãããããããã«ãApache Camelã¯ãã¢ããªã±ãŒã·ã§ã³ãçµ±åããããã®ã¢ãžã¥ãŒã«åŒã§ç°¡åã«æ¡åŒµå¯èœãªãã¬ãŒã ã¯ãŒã¯ã§ãã äž»ãªæ§é èŠçŽ ïŒã³ã³ããŒãã³ãã¢ãã«ãã«ãŒãã£ã³ã°ã¡ã«ããºã ãã¡ãã»ãŒãžåŠçã¡ã«ããºã ã ã³ã³ããŒãã³ãã¢ãã«ã¯ãã«ãŒãã£ã³ã°ãšã³ããã€ã³ããäœæãããã¡ã¯ããªã®ã»ããã§ãã ããšãã°ããšã³ããã€ã³ãã¯ããããŒã«ãŒã®JMSãã¥ãŒã«ã¡ãã»ãŒãžãéä¿¡ããæœè±¡åã§ããå ŽåããããŸãã ã«ãŒãã£ã³ã°ã¡ã«ããºã ã¯ããšã³ããã€ã³ããã¡ãã»ãŒãžåŠçã®æœè±¡åã«é¢é£ä»ããŸãã åŸè ã®ã¡ãã»ãŒãžåŠçã¡ã«ããºã ã«ãããã¡ãã»ãŒãžããŒã¿ãæäœã§ããŸãã ããšãã°ãå¥ã®åœ¢åŒãžã®å€æãæ€èšŒãæ°ããã³ã³ãã³ãã®è¿œå ããžã£ãŒãã«ãªã©ã 3ã€ã®ã¢ãŒããã¯ãã£ã³ã³ããŒãã³ãã¯ãã¹ãŠã¢ãžã¥ãŒã«åãããŠãããããã«ãããCamelã®æ©èœã¯åžžã«æ¡å€§ããŠããŸãã ãŠã£ãããã£ã¢ããã³å ¬åŒWebãµã€ãã§ãã¢ãŒããã¯ãã£ã®è©³çŽ°ãçç¥ã§ããŸãã ç»å Žããã°ããã®Apache Camelã¯ãã³ã³ããŒãã³ãã®å å®ãªã³ã¬ã¯ã·ã§ã³ãååŸããŸããã JMSãHTTPãftpããã¡ã€ã«ãSMTPãxPathãxsltãXStreamãGroovyãJavaãªã©ã®ãã¹ãŠã®èŠä»¶ãæºããã³ã³ããŒãã³ããèŠã€ãããŸããã Spring IntegrationãMule ESBãApache Camelã®ã©ã®çµ±åãã¬ãŒã ã¯ãŒã¯ã䜿çšãã¹ãããšããèè ã®ããã«ïŒ ããã£ã¡ã«ãéžã³ãŸããã ãã®èšäºã§ã¯ãSpring IntegrationãMule ESBãããã³Apache Camelã®3ã€ã®ãã¬ãŒã ã¯ãŒã¯ãæ¯èŒããŸãã èè ã¯ãäž»ãªå©ç¹ã次ã®ããã«èª¬æããŠããŸãã
... Apache Camelã¯ããã®çŽ æŽãããJavaãGroovyãããã³Scala DSLãšããµããŒããããŠããå€ãã®ãã¯ãããžãŒãçµã¿åããããŠããããã§ããäžåšçšãªXMLã®ä»£ããã«æµfluentãªJava DSLã䜿çšã§ããããšã¯ãç§ãã¡ã«ãšã£ãŠå€§ããªå©ç¹ã«ãªããŸããã åé¡ãçºçããŸãïŒäžåšçšãªãã®ã¯äœã§ããïŒ XMLã¯åªããããŒã¯ã¢ããèšèªã§ãããJSONãŸãã¯YAMLã§é·ãé奜ãŸããŠããŸããã ã·ã³ãã«ããèªã¿ãããã®åäžããµããŒãæ å ±ã®åæžã解æã¢ã«ãŽãªãºã ã®ç°¡çŽ åã®ããããããã奜ãŸããŠããŸãã JavaãGroovyãScalaãªã©ã®ããã°ã©ãã³ã°èšèªã¯ãææ°ã®IDEãå®å šã«ãµããŒãããŠããŸããã€ãŸããXMLãšã¯ç°ãªãããããã°ãšãªãã¡ã¯ã¿ãªã³ã°ãå¯èœã§ãã Camelã«ã¯çãã®äœå°ããããŸããã§ããããããŠããããç§ãã¡ã®ãµãŒãã¹ãã¹ã®åºç€ã圢æããŸããã ãã®ãããžã§ã¯ããä»ã®äŒæ¥ã«ãã£ãŠäœ¿çšããããšããäºå®ã¯ãæ£ããéžæã«å¯Ÿããä¿¡é Œãè¿œå ããŸããã
äž»ãªçåã¯æ®ããŸãã-ãã£ã¡ã«ãã¢ã³ã¹ã¿ãŒã«çµ±åããæ¹æ³ã
å°éºŠç²ïŒJMS vs RMIã
ãµãŒãã¹ãã¹ãšã¢ã³ã¹ã¿ãŒã®çµ±åã¯ãCamelããµããŒãããå€ãã®ã³ã³ããŒãã³ãã®1ã€ã䜿çšããŠå®è£ ã§ããŸãã äžèšã®ã¿ã¹ã¯ã«åºã¥ããŠãèŠä»¶ã圢æããŸãããéä¿¡ã¯å®å®ããã¡ãã»ãŒãžé ä¿¡ãä¿èšŒããå¿ èŠããããŸãã æåã®2ã€ã¯åæRMIãšHTTPã§ã1ã€ã¯éåæJMSã§ããã 3ã€ã®ãã¡ãJavaãããžã§ã¯ãã«é©ããæãåçŽãª2ã€ã®ããŒãžã§ã³ãJMSãRMIã«æ±ºããŸããã JMSïŒJavaã¡ãã»ãŒãžãµãŒãã¹ïŒã¯ãã¡ãã»ãŒãžãéä¿¡ããããã®æšæºã§ãããã¡ãã»ãŒãžã®éä¿¡ãåä¿¡ãäœæã衚瀺ã®ã«ãŒã«ãèŠå¶ããŸãã 2çªç®ã®RMIïŒRemote Method InvocationïŒã¯ããªã¢ãŒãããã·ãŒãžã£ãåŒã³åºãããã®ããã°ã©ãã³ã°ã€ã³ã¿ãŒãã§ã€ã¹ã§ãããããJVMã®ã¡ãœãããå¥ã®JVMã®ã³ã³ããã¹ãã§åŒã³åºãããšãã§ããŸãã æšæºã®ãªã¢ãŒãåŒã³åºãæé ã«ã¯ãJavaãªããžã§ã¯ãã®ããã¯ãšåãæž¡ããå«ãŸããŸãã å ¬å¹³ã«èšããšãJMSã¯ãã©ã³ã¹ããŒãã§ãããRMIã®äžå¯æ¬ ãªéšåã«ãªãå¯èœæ§ããããããJMSãšRMIã®å¯Ÿæ¯ã¯æ£ãããªãããšã«æ³šæããŠãã ããã æšæºã®RMIå®è£ ãšJMSå®è£ ã§ããActiveMQãæ¯èŒããŸãã 以åã¯ãRMIã䜿çšããŠ2ã€ã®ã¢ããªã±ãŒã·ã§ã³ãçµ±åããŸããã ãªã圌ã¯éžã°ããã®ã§ããïŒ äž¡æ¹ã®ã¢ããªã±ãŒã·ã§ã³ãJavaã§ããå ŽåãRMIã»ã©ç°¡åãªãã®ã¯ãããŸããã ããã䜿çšããã«ã¯ãã€ã³ã¿ãŒãã§ãŒã¹ãèšè¿°ãããã®ã€ã³ã¿ãŒãã§ãŒã¹ãå®è£ ãããªããžã§ã¯ããç»é²ããã ãã§ååã§ãã ããããã¢ããªã±ãŒã·ã§ã³éã§å€§éã®ããŒã¿ã転éãããšãã«RMIã§çºçããåé¡ã解決ããæ©äŒããããŸãããã¡ã¢ãªãè©°ãŸããã¢ããªã±ãŒã·ã§ã³ããã¹ã¿ãã¯ãããŸããã ãã®åé¡ã®è§£æ±ºçãæ¢ããJavaOne JVMéçºè ãšè°è«ããŸããã ä»®æ³ãã·ã³ã®ã¬ããŒãžã³ã¬ã¯ã¿ãŒãšåæ£ã³ã¬ã¯ã¿ãŒã¯2ã€ã®ç°ãªããã®ã§ããããšãå€æããŸããã ããã¯ãã¹ãŠãæšæºã®ã¬ããŒãžã³ã¬ã¯ã¿ãŒã§ã¯ãã®ã¿ã€ããéžæããŠæé©ãªãã©ã¡ãŒã¿ãŒãæ§æããããšãå¯èœã§ãããšããäºå®ã«ãããŸãããåæ£åã§ã¯ãã®ãããªå¯èœæ§ã¯ãããŸããã§ããã ä»ã®éãã«ã€ããŠè©±ããšãRMIã¯JVMäžã§å®è¡ãããã¢ããªã±ãŒã·ã§ã³ãžã®çµ±åãå¶éããŠããŸããããJMSã¯ããã§ã¯ãããŸããã§ããã èšèŒãããå°é£ã«å ããŠãRMIãæŸæ£ãã代æ¿ãœãªã¥ãŒã·ã§ã³ã䜿çšãããšããæ°ããããšãåŠã³ãããšããèŠæããããŸããã
ãã£ã¡ã«ã®æåã®ãããã¿ã€ã
ãããã¿ã€ãã®äœæã«æ»ããŸãããã ãµãŒãã¹ãã¹ã®æåã®å®çšçãªã¿ã¹ã¯ã¯ããã§ããããŠãŒã¶ãŒãããŒã¿ãã¢ããããŒãããããã»ã¹ãéå§ããã·ã¹ãã ããããæºåãããµãŒãã¹ãã¹ã«éä¿¡ããŸãã ãã¹ãŠã®ããŒã¿é ä¿¡äœæ¥ã¯åœŒå¥³ã«ããã£ãŠããŸãã ãã®å³ã¯ããšã³ã¿ãŒãã©ã€ãºã¢ããªã±ãŒã·ã§ã³çµ±åãã¿ãŒã³ïŒEIPïŒã®ã·ã³ãã«å ã®åé¡ã¹ããŒãã¡ã³ãã®äŸã瀺ããŠããŸãã
ãµãŒãã¹ãã¹ã¯ãJMSãã£ãã«ããã®ã¡ãã»ãŒãžã®åä¿¡ãå€æãããã³HTTPçµç±ã®éä¿¡ãçµã¿åãããŸãã å³ã«ããŒã¯ãããŠããJMSãã£ãã«ããã³HTMLã¡ãã»ãŒãžéä¿¡ãã£ãã«ã¯ãCamel JMSããã³Jettyã³ã³ããŒãã³ãã䜿çšããŠå®è£ ãããããšã«ãªã£ãŠããŸãã ããŒã¿å€æããã»ã¹ã¯ãJavaããã³/ãŸãã¯ãã³ãã¬ãŒããšã³ãžã³ïŒVMïŒApache VelocityïŒãªã©ïŒã䜿çšããŠå®è£ ã§ããŸãã ææ¡ãããããŒã¿è»¢éã¹ããŒã ã¯ãJava DSLã§1è¡ã§å®è£ ãããŸãã äŸïŒ
from("jms:queue:se.export") .setHeader(Exchange.HTTP_METHOD,constant(org.apache.camel.component.http.HttpMethods.POST)) .process( new JmsToHttpMessageConvertor() ) .inOnly("jetty:{{externalsystem.uri}}");
äžèšã®äŸã¯ãJava DSLã«ãŒãã瀺ããŠããŸãã ã«ãŒãã¯ãã¡ãã»ãŒãžéä¿¡ã«ãŒãã®èª¬æã§ãã Camelã«ã¯ãJava DSLãšXML DSLã®2çš®é¡ã®èšè¿°ããããŸãã ãã®ãããªã«ãŒãã®ç¹æ§ã¯ãéå§ç¹ãš1ã€ä»¥äžã®çµäºç¹ã§ãããããããfromãštokenã§ç€ºãããŸãã ã«ãŒãã¯ãéå§ç¹ããçµäºç¹ãŸã§ã®ã¡ãã»ãŒãžãã¹ãèšè¿°ããŸãã ãšã³ããã€ã³ããé çªã«ç€ºãããŠããå Žåãã¡ãã»ãŒãžã¯æåã®ãšã³ããã€ã³ãã«éä¿¡ããããµãŒãã¹ãã¹ã¯å¿çãåŸ ã£ãŠããã次ã®ãã€ã³ãã«éä¿¡ããŸãã ç®çã®ãšã³ããã€ã³ããéžæããã«ãŒãïŒ Dynamic Router ïŒããŸãã¯è€æ°ã®ãã€ã³ãã«ã¡ãã»ãŒãžãäžåºŠã«éä¿¡ããã«ãŒãïŒ Recipient List ïŒãååšããå ŽåããããŸãã fromããã³tokensãã©ã¡ãŒã¿ãŒã¯ãURIãå«ãæååã§ãã URIã¯ãCamelã³ã³ããŒãã³ãã®ååããªãœãŒã¹èå¥åãããã³æ¥ç¶ãã©ã¡ãŒã¿ãŒã§æ§æããã3ã€ã®ãã©ã¡ãŒã¿ãŒã§ãã äŸãèŠãŠã¿ãŸãããïŒ
from(âjms:queue:se.export?timeToLife=10000â)
ããã¯ãJMSã³ã³ããŒãã³ãã䜿çšãããšã³ããªãã€ã³ãã®èª¬æã§ãã JMSã³ã³ããŒãã³ãã¯ããã¥ãŒããããŒã¿ãååŸããæ©èœãæäŸããŸãïŒse.exportãªãœãŒã¹ã ãã¥ãŒã¯ã¡ãã»ãŒãžãã£ãã«ã®ã¿ã€ãã§ããããã¥ãŒãŸãã¯ãããã¯ã®ããããã§ãã 次ã«ããã£ãã«åãse.exportããæ¥ãŸãã ãã®ååã®ãã¥ãŒã¯ãã¡ãã»ãŒãžãããŒã«ãŒã«ãã£ãŠäœæãããŸãã URIã®æåŸã®éšåã§ãããšã³ããã€ã³ããã©ã¡ãŒã¿ãtimeToLife = 10000ãã¯ããã±ããã®ã©ã€ãã¿ã€ã ã10ç§ã§ããããšã瀺ããŸãã
ãã®äŸãããããŒã¿ã®è»¢éãã©ã®ããã«ç·šæããããæ確ã«ãªããŸããã次ã®èšäºã§ã¯ãããå®éã®ã³ãŒããšäŸããããŸãã
ããã§ãããŒã¿è»¢éã®åé¡ã解決ããCamelã§æ§æãããå®è£ ã®æºåãã»ãŒæŽã£ãçµ±åãã¹ã®ãããã¿ã€ããäœæããŸããã æ£ãã䟿å©ãªæ§æã®åé¡ã解決ããããã«æ®ã£ãã
ãããã¿ã€ãã®ã»ããã¢ãã
å®éã®ã¢ããã€ã¹ãå®è£ äŸãèŠã€ããã®ã¯é£ããããããã®ãããã¯ã«ã¯éåžžã«æéãåããŸããã
ã¹ã¿ã³ãã®æ§é ã¯æ¬¡ã®ãšããã§ãã
åéçºè ã¯ãœãããŠã§ã¢ã®ç¬èªã®ã³ããŒãææããŠããããããèµ·åããåã«å®å šã«æ§ââæããŸãã æåãã¹ãçšã«2ã€ã®ãã¹ããã³ããããããã¡ããåäœããã·ã¹ãã ããããŸãã åé¡ã®èª¬æã¯æ¬¡ã®ãšããã§ãã
- åã¹ã¿ã³ãã®åŸ®èª¿æŽã¯ãã·ã¹ãã æ§æãã¡ã€ã«å ã®ãã©ã¡ãŒã¿ãŒã®æå°æ°ãç·šéããã ãã§è¡ãå¿ èŠããããŸããã
- ãã¹ãŠã®ã¹ã¿ã³ãã§å€§èŠæš¡ãªã«ã¹ã¿ãã€ãºïŒæ°æ©èœã®è¿œå ïŒãã·ãŒã ã¬ã¹ã«å®è¡ãããŸãã
ãŸããéçºè ã®ã¹ã¿ã³ãã§ãããžã§ã¯ããã«ããŒïŒMavenïŒã䜿çšããããšã¯ã§ããŸãããããã¹ãã¹ã¿ã³ããšéçšãµãŒããŒã§ã¯äœ¿çšã§ããŸããã§ããã
ãã®ã¿ã¹ã¯ã«ã¯å€ãã®å°é£ããããŸããCamelã¯JMSãããŒã«ãŒãšæ¥ç¶ãããŠãããããç°ãªãã¹ã¿ã³ããŸãã¯ç°ãªãã¡ãã»ãŒãžãããŒã«ãŒã«ç°ãªããã£ãã«ã䜿çšããå¿ èŠããããŸãã ãã¹ã«çµ±åãããActiveMQãããŒã«ãŒãèµ·åããããšã«ãããæãç°¡åãªæ¹æ³ãå®è¡ããŸããã ãã®å Žåãç°ãªããµãŒããŒã«æ¥ç¶èšå®ãæäŸããããšã¯æ®ããŸãã
ãã£ã¡ã«èšå®ã§ãã©ã¡ãŒã¿ãŒã䜿çšããäŸã«ç§»ããŸãããã
- camel-config.xmlã®äŸ
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:system.properties</value> <value>classpath:smtp.properties</value> </list> </property> </bean>
ãã®äŸã§ã¯ãSpringã®2ã€ã®æ§æãã¡ã€ã«ãèšå®ããŸãã - åã®äŸã®2ã€ã®ãã¡ã€ã«ã§æå®ãããèšå®ã䜿çšããäŸã
<bean id="someServiceStartPolicy" class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy"> <property name="routeStartTime" value="${config.someService.routeStartTime}"/> <property name="routeStopTime" value="${config.someService.routeStopTime}"/> </bean>
ããããã£èªäœã¯ãã$ {config.someService.routeStartTime}ãè¡ã§èšå®ãããŸã
- è€æ°ã®èšå®ãã¡ã€ã«ãCamelã³ã³ããã¹ãã«è»¢éãããäŸ
<camelContext id="rootCamelRoute" xmlns="http://camel.apache.org/schema/spring"> <propertyPlaceholder id="properties" location="smtp.properties, system.properties"/> ⊠</propertyPlaceholder> </camelContext>
- Java DSLã®Camelã«ãŒãã§ãã©ã¡ãŒã¿ãŒã䜿çšããäŸ
from("jms:queue:email.send") .setHeader("to", simple("${headers.email}")) .setHeader("from", simple("${properties:config.smtp.from}")) .to("{{config.smtps.server}}?username={{config.smtps.user}}&password={{config.smtps.password}}&contentType=text/html&consumer.delay=60000")
ããã§ã¯ããã©ã¡ãŒã¿ãã¢ãã¬ã¹æå®ããããã€ãã®æ¹æ³ãäžåºŠã«äœ¿çšãããŸãã ããã«ãããŸãïŒ
-åçŽãªæ¹èšã§ã¯ãæååã$ {propertiesïŒconfig.smtp.to}ã
-æååã{{config.smtps.server}}ããæã€ãšã³ããã€ã³ãURI
ãã©ã¡ãŒã¿ãŒåã¯ä»»æã§ããè¡ã¯äžèšã®äŸããåãããŠããŸãã
æ¬åœã®åé¡ãæ³åããŠã¿ãŸãããã
ãµãŒãã¹ãã¹ãä»ããŠSMTPãµãŒããŒã«ã¬ã¿ãŒãéä¿¡ãããµãŒãã¹ããããŸãã ãã®ãããªãµãŒãã¹ã¯ã皌åäžã®ã·ã¹ãã ã®ãŠãŒã¶ãŒã«ã¡ãã»ãŒãžãéä¿¡ãããã¹ãã·ã¹ãã ã®å Žåããã¹ãŠã®ã¬ã¿ãŒã1ã€ã®ã¡ãŒã«ããã¯ã¹ã«éä¿¡ããå¿ èŠããããŸãã
次ã«ããã®ã¿ã¹ã¯ã¯ããã¹ãã·ã¹ãã ãšå®çšŒåã·ã¹ãã ã§å®è¡ãããããã€ãã®ã«ãŒãã«ç°ãªãããžãã¯ãè¿œå ããããã«å€æãããŸãã
ãã£ã¡ã«ã«ãŒãã®ãã©ã¡ãŒã¿ãŒã䜿çšããŠããã®ãããªåé¡ã解決ããæ¹æ³ã®äŸã次ã«ç€ºããŸãã
from("jms:queue:event.recoverypass") .setHeader("to", isDebug() ? simple("${properties:config.smtp.to}") : simple("${headers.email}")) .setHeader("from", simple("${properties:config.smtp.from}")) ⊠// some other headers .choice() .when( header("password").isNotNull() ) .setHeader("subject", simple("${properties:config.passwordNotify}")) .to("velocity:vm/email/newPasswordNotify.vm") .otherwise() .setHeader("subject", simple("${properties:config.recoverypass}")) .to("velocity:vm/email/recoveryPassword.vm") .end() .to("{{config.smtps.server}}?username={{config.smtps.user}}&password={{config.smtps.password}}&contentType=text/html&consumer.delay=60000")
äžèšã®ãµã³ãã«ã³ãŒãã¯ããã¹ã¯ãŒãå埩ãµãŒãã¹ã«å¿ èŠã§ãã 次ã®ããžãã¯ãå®è£ ãããŸãïŒãŠãŒã¶ãŒããã¹ã¯ãŒãã®ãªã»ãããã¿ã³ãã¯ãªãã¯ããæ°ãããã¹ã¯ãŒããçæããããã®äžæãªã³ã¯ãå«ãé»åã¡ãŒã«ããŠãŒã¶ãŒã«éä¿¡ããããŠãŒã¶ãŒããªã³ã¯ãã¯ãªãã¯ããåãã«ãŒãããŠãŒã¶ãŒã«æ°ãããã¹ã¯ãŒããã¡ãŒã«ã§éä¿¡ããŸãã ããã¯ããããæåã®éšåãå®äºããã¹ãå Žæã§ãããããã¯åšåº«ãåãããã ãã«æ®ã£ãŠããŸãã
ãŸãšã
ãã¹ã®ãããã¿ã€ããå®æããŸãããã¡ãã»ãŒãžãéä¿¡ããããã®ããã€ãã®ã«ãŒããç»å Žãããã¹ã®æ§æãšå±éã容æã«ããæ§æãã¡ã€ã«ãç»å ŽããŸããã ãã£ã¡ã«ããã¹ã¿ãŒããæåã®ã¹ãããã®çµæã«ããã°ããã®ãããªã¢ãããŒãã®å€§ããªå¯èœæ§ã«ã€ããŠè©±ãããšãã§ããŸãã ã«ãŒãäœæã®ã·ã³ãã«ããšç°¡æœããé åçã§ãã ãã¹ãŠã1è¡ã§å®è¡ã§ããããã§ãã ãã ããã«ãŒãã®æäœã«ã¯èãæ¹ã®å€æŽãå¿ èŠã§ãããšããäºå®ã«æ³šæããå¿ èŠããããŸãã ãããã«å¯ŸåŠããªãã£ãããã°ã©ããŒã«ãšã£ãŠã¯ãããã«ããšã³ã¿ãŒãã©ã€ãºã¢ããªã±ãŒã·ã§ã³ã®çµ±åãã³ãã¬ãŒãããšããæ¬ã«ç®ãåããããšãæåã§ãã çµ±åãã¿ãŒã³ãç解ããããšã®å¹æã¯ãåŸæ¥ã®OOPã§èšèšãã¿ãŒã³ãç¥ãããšã®å¹æã«å¹æµããŸãã
ããããªããããããªãã 次ã®ããŒãã§ãäŒãããŸãããã ãã£ã¡ã«ã®ãŠãŒã¹ã±ãŒã¹ã«å°å¿µããããšãæãåºãããŠãã ããã