ããŒã¿ã亀æããå¿
èŠã®ããå°ãªããšã2ã€ã®æ
å ±ã·ã¹ãã ãäŒç€Ÿã«çŸãããšããã«ãçžäºäœçšãæŽçããæ¹æ³ã®åé¡ãçããŸãã å€ãã®ãªãã·ã§ã³ããããŸãïŒãã¡ã€ã«äº€æãããŒã¿ããŒã¹éã®ãªã³ã¯ããŠã§ããŸãã¯æ®ãã®ãµãŒãã¹ãããŸããŸãªã¡ãã»ãŒãžã³ã°ã·ã¹ãã ãå€ãRPCãšCORBAãææ°ã®gRPCãªã©ã éžæã¯ããããžã§ã¯ãåå è
ã®å¥œã¿ãšã·ã¹ãã ã®æ©èœïŒã·ã¹ãã ã¢ãŒããã¯ãã£ã䜿çšãããã©ãããã©ãŒã ãæ¢è£œã®APIã®å¯çšæ§ãªã©ïŒã«äŸåããŸãã äœããã®äº€æãéžæãããšãã·ã¹ãã ãçžäºäœçšãå§ãããã¹ãŠãããŸããããšä»®å®ããŸãã ãããããã®åŸã3çªç®ã®ã·ã¹ãã ãçºçããããã«çµ±åããå¿
èŠãããã4çªç®ãªã©ãç¶ããŸãã ãã§ã«äœ¿çšãããŠããæè¡ã«èªåèªèº«ãå¶éããããšã¯ã§ããªããšããäºå®ã§ã¯ãªããåã³åº§ã£ãŠäº€æã®æ¹æ³ãéžæããå¿
èŠããããŸãïŒæ°ããã·ã¹ãã ã®å¶éã«ãããã©ããã§éçºè
ãå¥ã®æè¡ã䞻匵ããããäœãæ°ããããšãè©ŠããŠã¿ããã£ãïŒã ã·ã¹ãã ã®æ°ãå¢ãããšãã·ã¹ãã éã®çžäºäœçšã®æ°ãšè€éããå¢ãã䜿çšããããã¯ãããžãŒã®æ°ãå¢ããŸãã ãã®çµæãäŒç€Ÿã®çµ±åã¢ãŒããã¯ãã£å
šäœããè²ã糞ã®ãã€ããããŒã«ã®ããã«ãªãå§ããäŒç€Ÿã®ã·ã¹ãã ãäœããã®åœ¢ã§ãªã³ã¯ããŸãã é
ããæ©ããããã¹ãŠã®ã·ã¹ãã ãééçãã€æ¡åŒµå¯èœã«ãªã³ã¯ããåäžã®çµ±åç°å¢ãäœæããããšãèãããå§ããŠããŸãã
ãã®èšäºã§ã¯ãApache ServiceMixïŒCamelïŒãšRabbitMQã䜿çšããŠãã®ãããªçµ±åç°å¢ãæ§ç¯ããçµéšã«ã€ããŠèª¬æããŸãã
æè¡ã¹ã¿ãã¯
ããã
RabbitMQã¯ãAMQPãããã³ã«ã«åºã¥ãã¡ãã»ãŒãžã³ã°ã·ã¹ãã ã§ãã ã·ã¹ãã ã®è©³çŽ°ã¯èª¬æããŸãããHabréã«ã¯ãã·ã¹ãã ã®æ©èœã詳现ã«èª¬æããèšäºãæ¢ã«ããã€ããããŸããRabbitMQã®äœ¿çšå Žæãšäœ¿çšæ¹æ³ã«ã€ããŠèª¬æããŸãã
RabbitMQãéããŠãäŒç€Ÿã®æ
å ±ã·ã¹ãã ãšããŒã¿ã亀æããŸãã åã·ã¹ãã ã«å¯ŸããŠäžé£ã®ãã¥ãŒãäœæãããŸãã ããšãã°ãäŒèšã·ã¹ãã ã§é¡§å®¢ã®æ€çŽ¢ãååãšç幎ææ¥ã§æŽçããå¿
èŠããããŸãã ããã€ãã®ãã¥ãŒãäœæããŸãã äŒèšã·ã¹ãã ã«é¢ããŠã¯ãã¯ã©ã€ã¢ã³ãã®ååãšç幎ææ¥ã瀺ããªã¯ãšã¹ããéä¿¡ããŸãã ã¢ã«ãŠã³ãã£ã³ã°ã·ã¹ãã ã¯çä¿¡ãã¥ãŒããªãã¹ã³ããçä¿¡èŠæ±ãåŠçããŸãã 2ã€ç®ã¯çºä¿¡ã§ããã¢ã«ãŠã³ãã£ã³ã°ã·ã¹ãã ã¯ãèŠæ±ã®æ¡ä»¶ã«äžèŽããã¯ã©ã€ã¢ã³ãã®ãªã¹ããå«ãå¿çãéä¿¡ããŸãã
䟿å©ãªçç±ïŒ
- ãã¥ãŒã«ä¿åãããŠããã¡ãã»ãŒãžã¯æ°žç¶çã§ãã ã€ãŸã ã·ã¹ãã ããã°ããå©çšã§ããªãå Žåãã¡ãã»ãŒãžã¯ã©ãã«ãæ¶ãããã·ã¹ãã ã®èµ·ååŸã«åŠçãããŸãã RabbitMQèªäœãåèµ·åããŠããã¡ãã»ãŒãžã¯å€±ãããŸããã
- ãã¥ãŒã¯ãã·ã¹ãã ãå¿«é©ãªã¢ãŒãã§åŠçã§ãããããã¡ãšããŠæ©èœããããŒã¯è² è·ãåé¿ããŸãã ãŠãŒã¶ãŒãã€ã³ã¿ãŒãã§ã€ã¹ã§åŸ
æ©ããŠãããªã¯ãšã¹ãã§ã¯ããããæ©èœããªãããšã¯æããã§ãã ãã®å Žåãå³æã®å¿çãå¿
èŠã§ãã ããããããããçš®é¡ã®éåæçžäºäœçšã«ã¯éåžžã«é©ããŠããŸãã
- éåæã¢ãŒãã®çžäºäœçšã åæã«ãåæåŒã³åºãããµããŒããããŠããŸãã
RabbitMQãšå¯Ÿè©±ããããã«ã·ã¹ãã ãæããããšã¯é£ãããããŸããã RabbitMQã«ã¯ãããŸããŸãªãã©ãããã©ãŒã ïŒJavaã.NetãPythonãªã©ïŒçšã®æ¢è£œã®ã¯ã©ã€ã¢ã³ãããããŸãã ã¯ã©ã€ã¢ã³ãã¯ã·ã³ãã«ã§ç°¡åã§ãã ãã¥ãŒããã¡ãã»ãŒãžãèªã¿åããããã³/ãŸãã¯ãã¥ãŒã«ã¡ãã»ãŒãžãéä¿¡ããã³ãŒãã¯ãæ°è¡ããããŸãã ãã¹ãŠã®ã·ã¹ãã ãRabbitMQãšåéã«ãªããããã§ã¯ãªãããšã¯æããã§ããããšãã°ãã¬ã¬ã·ãŒã·ã¹ãã ãããã¯ã¹åãããã·ã¹ãã ã®å Žåãããã¯å°é£ã§ãã ãã®å Žåã亀æã¯ããããã®ã·ã¹ãã ããµããŒããããã¯ãããžãŒã䜿çšããŠæ§ç¯ãããŸããããŒã¿ããŒã¹ã®ã¹ãã¢ãããã·ãŒãžã£ãåŒã³åºãå ŽæãWebãµãŒãã¹ãšäŒæ©ãµãŒãã¹ã䜿çšããå Žæãä»ã®å Žæã§ãã ä»ã®å€ãã®çµ±åã¿ã¹ã¯ã®ããã«ãã®ãããªå¯Ÿè©±ãæŽçããããã«ãApache ServiceMix補åã䜿çšãããŸãã
Apache ServiceMix
ServiceMix-ããŸããŸãªçµ±åã®åé¡ã解決ããã®ã«åœ¹ç«ã€äºåå®çŸ©ããããã³ãã«ã®ã»ãããæã€Karafã³ã³ãããŒã
補åã«å«ãŸãããã®ã«ã€ããŠããå°ã詳ããïŒ
- å®éã«ã¯ããã³ãã«ãæ©èœãããããã管çã§ããKarafã³ã³ããèªäœïŒã€ã³ã¹ããŒã«/ã¢ã³ã€ã³ã¹ããŒã«/åæ¢/éå§ããã°ã®è¡šç€ºãã³ã³ããŒãã³ãã®äŸåé¢ä¿ã®ç¢ºèªãªã©ã
- æ€èšŒãããŸããŸãªå€æïŒJSONããXMLãžã®å€æãXSLTã䜿çšããå€æãªã©ïŒã匷åãã«ãŒãã£ã³ã°ãåå²ãšçµåãç£èŠãçµ±åããã»ã¹ã®å®è¡ãªã©ãå€å
žçãªçµ±åæ©èœãå®è¡ããå¹
åºããã³ãã«ã ã
- å¹
åºãçš®é¡ã®ã¢ããã¿ãŒïŒãã¡ã€ã«ã¢ããã¿ãŒãWebããã³RESTãµãŒãã¹çšã¢ããã¿ãŒãJMSãRabbitMQãKafkaãªã©ã ã¢ããã¿ãŒã®å®å
šãªãªã¹ãã¯ãCamel Webãµã€ãã«ãããŸãã
äºåã«ã€ã³ã¹ããŒã«ããããã³ãã«ã®ã¿ã䜿çšããããšã«éå®ãããããšã¯ã»ãšãã©ãããŸããããã€ã³ã¹ããŒã«ãããã»ãããèµ·åããã«ã¯ååãªã¯ãã§ãã ãªããªã ç§ãã¡ã¯Karafã³ã³ããã䜿çšããŠãããããå¿
èŠãªãã³ãã«ãã€ã³ã¹ããŒã«ã§ããŸããããã¯ãæ©èœïŒãã³ãã«ã»ããïŒãã€ã³ã¹ããŒã«ããããåã
ã®ãã³ãã«ãã€ã³ã¹ããŒã«ããã ãã§å®è¡ã§ããŸãã ãã¡ãããç¬èªã®ãã³ãã«ãäœæããããšãããµãŒãããŒãã£ã®Javaã©ã€ãã©ãªããã³ãã«ã«ã©ããããããšãã§ããŸãã
ã¢ããããã£ã¡ã«
ServiceMixã®äž»èŠãªã³ã³ããŒãã³ãã¯Apache Camelãã¬ãŒã ã¯ãŒã¯ã§ããããã«ãããCamelçšèªã§ã«ãŒããšåŒã°ããçµ±åããã»ã¹ãæ§ç¯ã§ããŸãã
äŸã瀺ããŸããã-ã«ãŒããšã¯äœã§ããïŒ
ããã¯ãåä¿¡ãããã«ããã©ãŒãããã¡ãã»ãŒãžãå
±éã®åºåãã©ãŒãããã«å€æããåçŽãªã«ãŒãã®äŸã§ãã ã¡ãã»ãŒãžã®åœ¢åŒã«å¿ããŠãã«ãŒãã¯ã¡ãã»ãŒãžãé©åãªå€æã«ã«ãŒãã£ã³ã°ããŸããå€æã¯ãã¡ãã»ãŒãžãå
±éã®åœ¢åŒã«å€æããçµæãåºåã«éä¿¡ããŸãã
Camelã¯ãã«ãŒããæãäžè¬çãªJava DSLããã³Spring XMLã®èšè¿°ã®ããã®ããŸããŸãªè¡šèšæ³ããµããŒãããŠããŸãã Spring XMLã䜿çšããŸãã Spring XMLè¡šèšã§ã¯ãç»åã®ã«ãŒãã¯æ¬¡ã®ããã«ãªããŸãã
<route id="Normalizer"> <from uri=" endpoint" /> <choice> <when> <xpath>/*[local-name()='Format_1']</xpath> <to uri="xslt:classpath:xslt/Format_1_Transformation.xslt" /> </when> <when> <xpath>/*[local-name()='Format_2']</xpath> <to uri="xslt:classpath:xslt/Format_2_Transformation.xslt" /> </when> <when> <xpath>/*[local-name()='Format_3']</xpath> <to uri="xslt:classpath:xslt/Format_3_Transformation.xslt" /> </when> </choice> <to uri=" endpoint" /> </route>
éåžžã«çŽ æŽãããè¿œå æ©èœã¯ãCamelãSpringãšå®å
šã«çµ±åãããŠããããšã§ãã Beanãå®çŸ©ãã䜿ãæ
£ããSpring XMLã䜿çšããåãSpring XMLã§Camelã«ãŒããå®çŸ©ã§ããŸãã åæã«ããã³ã¯ã«ãŒãããåŒã³åºãããšãã§ããã«ãŒãã¯ãã³ããåŒã³åºãããšãã§ããŸãã ã«ãŒãããã®ãã³ã®åŒã³åºãã¯Camelåºæã®æè»æ§ã§å®è£
ãããã¡ãã»ãŒãžæ¬æãBeanã¡ãœããã«æž¡ãããããããŒ+æ¬æãæž¡ãããšãã§ããŸãããŸãã¯ãXPATHåŒã§æå®ãããç¹å®ã®XMLã¡ãã»ãŒãžã¿ã°ã®å€ã®ã¿ãæž¡ãããšãã§ããŸããã«ãŒãã ãããŠããããã¯ãã¹ãŠå®è³ªçã«1è¡ã«ãŸãšããããŠããŸãã
ãã£ã¡ã«ã¹ã¿ã€ã«ã®ãšã¬ã¬ã³ã¹ã®äŸã次ã«ç€ºããŸãã
<camel:camelContext> <route id="Bean method invocation"> <from uri=" endpoint" /> <when> <simple>${bean:authManager?method=checkToken(${body})}</simple> <to uri=" " /> </when> </route> </camel:camelContext> <bean id="authManager" class="pachage.AuthManager" />
public class AuthManager { public boolean checkToken(@Body Document xml, @XPath("/Root/Token/@Value") String token) { return checkSessionToken(token); } }
Camelã®ãã1ã€ã®éèŠãªæŠå¿µã¯ããšã³ããã€ã³ãïŒä»¥éããšã³ããã€ã³ãïŒã§ãã ã«ãŒãã¯ãšã³ããã€ã³ãããã¡ãã»ãŒãžãèªã¿åãããšã³ããã€ã³ãã«ã¡ãã»ãŒãžãéä¿¡ã§ããŸãã ãšã³ããã€ã³ãã¯ãããšãã°ãRabbitMQãã¥ãŒããã£ã¬ã¯ããªå
ã®ãã¡ã€ã«ãå
¬éãããäŒæ©ãµãŒãã¹ãªã©ã§ãã ã«ãŒãããšã³ããã€ã³ããèªã¿åãå Žåãã¡ãã»ãŒãžããã®ãšã³ããã€ã³ãã«å°çãããšãã«ãŒãã¯ãããåŠçãå§ããŸãã ããã«ãããã«ãŒããå
¬éã§ããŸãã å€éšã·ã¹ãã ã«ã¢ã¯ã»ã¹ããæ©èœãæäŸããŸãã ããšãã°ãã¢ã³ã±ãŒãã«å
¥åãããããŒã¿ã®æ£ç¢ºæ§ã確èªãããªã©ãã¿ã¹ã¯ãå®è¡ããã«ãŒããããå Žåã¯ããããWebãµãŒãã¹ãšããŠå
¬éããããJMSãä»ããŠã¢ã¯ã»ã¹ã§ããããã«ããããå€éšã«äž¡æ¹ãè¡ãããšãã§ããŸãã·ã¹ãã ã¯ãã«ãŒãã®æ©èœãå©çšã§ããŸããWebãµãŒãã¹ãžã®åŒã³åºããä»ãããã®ãšãJMSãã¥ãŒãä»ããã¡ãã»ãŒãžã³ã°ãä»ãããã®ããããŸãã
ã«ãŒããçžäºã«ããåãã§ããããã«ããšã³ããã€ã³ãã䜿çšãããŸãã ããã«ãŒãã¯ãå¥ã®ã«ãŒããèªã¿åããšã³ããã€ã³ãã«ã¡ãã»ãŒãžãéä¿¡ããåŠçã®ããã«ã¡ãã»ãŒãžãæž¡ãããšãã§ããŸãã ããã«ãããã¢ããªã±ãŒã·ã§ã³ã®ããŸããŸãªå Žæã§èŠæ±ãããããŸããŸãªæ©èœãå®è£
ããã«ãŒãã®ç¬èªã®ãã¬ãããäœæã§ããŸãã ããšãã°ããã°ã¡ãã»ãŒãžã æ¯ååãäžé£ã®ãã°ã¢ã¯ã·ã§ã³ãå®è¡ãã代ããã«ãç¹å¥ã«èšèšãããã«ãŒãã«ã¡ãã»ãŒãžåŠçãåçŽã«è»¢éã§ããŸãã
çµ±åã¢ãŒããã¯ãã£
åœç€Ÿã¯å€ãã®æ
å ±ã·ã¹ãã ã䜿çšããŠããŸãã ã·ã¹ãã ãããŒã¿ã亀æããããã®çµ±åç°å¢ãç·šæããã«ã¯ããŸãã·ã¹ãã ãçµ±åãã©ãããã©ãŒã ã«æ¥ç¶ããå¿
èŠããããŸãã ãã®ãããServiceMixäžã®åã·ã¹ãã ã«å¯ŸããŠã¢ããã¿ãŒãéçºãããŠãããã·ã¹ãã ãšã®ããŒã¿äº€æããã³ããŒã¿åœ¢åŒã®å€æãæ
åœããŸãã
ã·ã¹ãã ããšã«ãã·ã¹ãã ãšServiceMixã®éã§1ã€ã®ããŒã¿äº€æãã¯ãããžãŒãéžæãããŸãã è€æ°éžæã§ããŸãããããã«ããã·ã¹ãã åŽãšServiceMixåŽã®äž¡æ¹ã§å®è£
ãè€éã«ãªããŸãã äžè¬çãªå Žåãããã€ãã®ç°ãªãæè¡ã®äœ¿çšã¯æ£åœåãããŸããããæè¡çã«å®è£
ããããšãã§ããŸãã ã·ã¹ãã ãšã®äº€æã«ã¯äž»ã«RabbitMQã䜿çšããŸãïŒServiceMixãçµ±åã·ã¹ãã ãšã¡ãã»ãŒãžã亀æãããã¥ãŒã®ã»ãããäœæããŸãïŒã ãã ããServiceMixã®äžéšã§ããæ¢è£œã®ã¢ããã¿ãŒã®ã»ãããæ¬åœã«åœ¹ç«ã€å ŽåããããŸãã ããšãã°ãäŒèšã·ã¹ãã ã®å ŽåãããŒã¿ããŒã¹å
ã®ã¹ãã¢ãããã·ãŒãžã£ã䜿çšããŸãã ã¹ãã¢ãããã·ãŒãžã£ãåŒã³åºãã«ã¯ãMyBatisã³ã³ããŒãã³ãã䜿çšããŸããããã«ãããServiceMixãçµç±ããã¡ãã»ãŒãžãã¹ãã¢ãããã·ãŒãžã£ãã©ã¡ãŒã¿ã«ãããã§ããŸãã 以äžã«ãIDã«ãããŠãŒã¶ãŒãžã®ãã°ã€ã³ã®ã€ã³ã¹ããŒã«ã®ãããã³ã°ã®äŸã瀺ããŸãã
<select id="setLogin" statementType="CALLABLE" parameterType="java.util.Map"> {call esb.SetLogin ( @UserId=#{UserId, mode=IN}, @LoginId=#{LoginId, mode=IN} )} </select>
ã¢ããã¿ã¯ãã·ã¹ãã ãçµ±åãã©ãããã©ãŒã ãšå¯Ÿè©±ãã圢åŒãå
éšåœ¢åŒã«å€æãã圹å²ãæãããŸãã 誰ããç¬èªã®XML圢åŒã䜿çšããJSON圢åŒã§ã®äº€æã奜ã人ãããŸãããçµ±åãã©ãããã©ãŒã å
ã§ã¯ãã³ã³ããŒãã³ãã¯å
éšæšæºXML圢åŒã§ããŒã¿ã亀æããŸãã çŸåšãXMLã¯ããã®éããšãJSONãProtobufãªã©ã®æ°ãã代æ¿æ段ã«ãã人æ°ã倱ã£ãŠããŸãã ããããç§ã®æèŠã§ã¯ãXMLã¯äŸç¶ãšããŠçµ±åã®åé¡ã解決ããã®ã«äŸ¿å©ã§ãã XSLTãXPATHãªã©ãç掻ã倧å¹
ã«ç°¡çŽ åããå€ãã®äŸ¿å©ãªãã¯ãããžãŒããããŸãããå®å
šã«äººéãèªãããšãã§ããŸãã
ã³ã³ããŒãã³ãïŒã¢ããã¿ãŒïŒéã®ã¡ãã»ãŒãžã«ãŒãã£ã³ã°ã¯ãã«ãŒãã£ã³ã°ã«ãŒã«ã«åºã¥ããŠããŸãã çµ±åãã©ãããã©ãŒã ã®1ã€ã®ã³ã³ããŒãã³ãå
ã®ã«ãŒãã¯ãCamelã®å
éšãšã³ããã€ã³ãïŒçŽæ¥ãsedaïŒãä»ããŠçžäºäœçšããŸãã çžäºéã§ãã³ã³ããŒãã³ãã¯RabbitMQãã¥ãŒãä»ããŠäº€æããŸãã ããã«ãããçµ±åãã©ãããã©ãŒã ã®ã³ã³ããŒãã³ããç¬ç«ãããããšãã§ããŸãã 1ã€ã®ã³ã³ããŒãã³ããèœã¡ãŠããä»ã®ã³ã³ããŒãã³ãã®ããã©ãŒãã³ã¹ã«ã¯åœ±é¿ããŸããã è² è·ãäžæçã«å¢å ãããšãã¡ãã»ãŒãžã¯ã³ã³ããŒãã³ããã¥ãŒã«èç©ãããæ®ãã®äº€æã«ã¯åœ±é¿ããŸããã
ãã®ãããªã¢ãŒããã¯ãã£ãããã€ã³ãããŒãã€ã³ãããŒã¹ã®ã·ã¹ãã éã®çŽæ¥çãªå¯Ÿè©±ãããåªããŠããçç±ïŒ
- åã·ã¹ãã ã¯ã1ã€ã®ãããã³ã«ãšå¯Ÿè©±åœ¢åŒã®ã¿ããµããŒãããå¿
èŠããããŸãã
- ä»ã®ã·ã¹ãã ãšã®äº€æã®è©³çŽ°ã¯ãçµ±åãã©ãããã©ãŒã ã®èåŸã«ããã·ã¹ãã ããé ãããŠããŸãã ã·ã¹ãã ã¯çµ±åãã©ãããã©ãŒã ãšã®ã¿å¯Ÿè©±ããä»ã®ã·ã¹ãã ã®ååšããèªèããŠããªãå ŽåããããŸããå°ãªããšãããããšã®å¯Ÿè©±ã®æ©èœã«ã€ããŠã¯å¿é
ããªãã§ãã ããã
- ã·ã¹ãã ã¯ççµåã§ãããããããšãã°ãããã·ã¹ãã ãæ°ããã·ã¹ãã ã«äº€æããå¿
èŠãããå Žåãªã©ãæè»æ§ãåäžããŸãã
- ç£èŠããã¹ããçµ±åãµããŒãã®ããã®ããŒã«ã¯ãçµ±åãã©ãããã©ãŒã ã®åŽé¢ã«éäžåãããŠããŸãã
èé害æ§
RabbitMQã¬ãã«ã§ã®ãã§ãŒã«ãªãŒããŒã¯ãã¯ã©ã¹ã¿ãŒãäœæãããã¥ãŒãåæããããšã«ããå®çŸãããŸãã RabbitMQããŒãã®1ã€ã§ãã¥ãŒã«å
¥ãåã¡ãã»ãŒãžã¯ãåæããªã·ãŒã«åŸã£ãŠä»ã®ããŒãã«è€è£œãããŸãïŒã¯ã©ã¹ã¿ãŒã®ãã¹ãŠã®ããŒãã«è€è£œã§ããŸããç¹å®ã®æ°ã®ããŒãã«è€è£œã§ããŸããããŸã£ããè€è£œã§ããŸããïŒã ãã¹ãŠã®ããŒãã«å¯ŸããŠã¡ãã»ãŒãžã¬ããªã±ãŒã·ã§ã³ãåãã3ããŒãæ§æã䜿çšããŸãã ããã«ããã3ã€ã®ããŒãã®ãã¡2ã€ãèœã¡ãå Žåã«ã¯ã©ã¹ã¿ãŒã®å®å
šãªæäœæ§ãç¶æã§ããŸãã ãã ããããã¯åã¡ãã»ãŒãžã®åŠçæéãšå æãã£ã¹ã¯å®¹éã®ç¹ã§æãã³ã¹ãã®ããããªãã·ã§ã³ã§ãããããšãç解ããå¿
èŠããããŸãã 3ã€ã®ããŒãã¯ãã¹ãŠã¯ã©ã€ã¢ã³ãäžã§RabbitMQã«ç»é²ãããŸãããæ¥ç¶ã¯ããŒãã®1ã€ãšéããŸãããæ¥ç¶ãåæãããå Žåãã¯ã©ã€ã¢ã³ãã¯ééçã«ä»ã®ããŒãã«åãæ¿ããŠåäœãç¶ããŸãã
ServiceMixã®ãã©ãŒã«ããã¬ã©ã³ã¹ã¯ã2ã€ã®ServiceMixããŒãã®ã¯ã©ã¹ã¿ãŒã䜿çšããŠå®çŸãããŸãã åæã«ãããã蚱容ãããå Žåããã³ãã«ã®äžéšã¯äžŠè¡ããŠåäœããŸãã ããšãã°ã1ã€ã®RabbitMQãã¥ãŒãèªã¿åãã¢ããã¿ãŒã¯ã䞊è¡ããŠå®è¡ã§ããŸãããã®ãã¡ã®1ã€ã ããåžžã«1ã€ã®ã¡ãã»ãŒãžãåä¿¡ããŸãããåæã«ã¡ãã»ãŒãžã¯2ã€ã®ããŒãéã§åçã«åæ£ãããŸãã ããŒãã®1ã€ãèœäžããå Žåã2çªç®ã®ããŒããå
šè² è·ãåŒãåããŸãã äžéšã®ãã³ãã«ã¯1ã€ã®ããŒãã§ã®ã¿ã¢ã¯ãã£ãã«ãªããŸããããã©ãŒã«ããŠã³ãããšã2çªç®ã®ããŒãã§ãã³ãã«ãã¢ã¯ãã£ãã«ãªããŸãã ããšãã°ãã¢ããã¿ãå
±æãããã¯ãŒã¯ãã£ã¬ã¯ããªãèªã¿åãå Žåãåããã¡ã€ã«ãåæã«èªã¿åããšãè€è£œãšè¡çªãçºçããå¯èœæ§ããããŸãã ãã®åäœã¢ãŒãã¯ãHazelcastã«åºã¥ãå
±æããã¯ã䜿çšããŠå®çŸãããŸãã æåã«ããã¯ããã£ããã£ãããã³ãã«ã¯ã¢ã¯ãã£ãã¢ãŒãã«ãªãããã®æ©èœãå®è¡ãã2çªç®ã®ãã³ãã«ã¯ããã¯ã解é€ãããã®ãåŸ
ã£ãŠãã³ã°ããŸãã
ãããŒã¯ãŒã«ã
çµè«ãšããŠãServiceMixã§å®è¡ããCamelã®Hello worldã¢ããªã±ãŒã·ã§ã³ã®ç°¡åãªäŸãæããããšæããŸãã ã¢ããªã±ãŒã·ã§ã³ã¯ããã³ãã«ã®éå§æïŒãã³ãã«ã®ãããã€æãServiceMixã®åèµ·åæãªã©ïŒã«ServiceMixãã°ã«ãHello worldããšãããã¬ãŒãºã1åæžã蟌ãã ãã§ãã
- ServiceMixãã£ã¹ããªãã¥ãŒã·ã§ã³ãããŠã³ããŒãããservicemix.shïŒbatïŒã解åããŠå®è¡ããŸãã
- æ°ããMavenãããžã§ã¯ããäœæããŠæ§æããŸãã
src / main / resourcesã§ãspringãµããã£ã¬ã¯ããªãäœæããMETA-INFãã£ã¬ã¯ããªãäœæããå¿
èŠããããŸãã
ãªããªã ãã³ãã«ããã«ãããå¿
èŠããããŸã-pom.xmlãç·šéããŸãïŒããã±ãŒãžåãšãã«ãã®æé ãè¿œå ïŒïŒ
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>HelloWorld</groupId> <artifactId>HelloWorld</artifactId> <version>1.0.0-SNAPSHOT</version> <name>HelloWorld</name> <description>HelloWorld</description> <packaging>bundle</packaging> <build> <plugins> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>3.0.1</version> <extensions>true</extensions> <configuration> <instructions> <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> <Import-Package>*</Import-Package> <Export-Package>${project.groupId};version=${project.version}</Export-Package> </instructions> </configuration> </plugin> </plugins> </build> </project>
Mavenã®äŸåé¢ä¿ãè¿œå ããå¿
èŠã¯ãããŸããã
- Camelã³ã³ããã¹ããšã«ãŒããæ§æããŸãã
springãã£ã¬ã¯ããªã§camel-context.xmlãã¡ã€ã«ãäœæããå¿
èŠããããŸãïŒããŒããŒã¯META-INF / springã§Camelã³ã³ããã¹ãèšè¿°ãã¡ã€ã«ãèªåçã«æ€çŽ¢ããã«ãŒããéå§ããŸãïŒã camel-context.xmlãã¡ã€ã«ã«ã次ã®ã³ã³ãã³ããæ¿å
¥ããŸãïŒããã¹ãã«æ²¿ã£ãŠã³ã¡ã³ãã衚瀺ãããŸãïŒã
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns:camel="http://camel.apache.org/schema/spring" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <camel:camelContext xmlns="http://camel.apache.org/schema/spring" id="HelloWorldContext"> <route id="HelloWorldRoute"> <from uri="timer://startTimer?repeatCount=1" /> <setBody> <constant>Hello world</constant> </setBody> <log message="${body}"/> </route> </camel:camelContext> </beans>
ã«ãŒããã¿ã¹ã¯ãå®äºããïŒãHello worldããšããããã¹ããèšé²ããïŒããã«ãã¡ãã»ãŒãžãéä¿¡ããå¿
èŠããããŸãã ãã®å Žåããã®ã¿ã¹ã¯ã¯timer <from uri = "timerïŒ// startTimerïŒRepeatCount = 1" />ã«ãã£ãŠè§£æ±ºãããŸããããã¯ã repeatCount = 1åœä»€ã«ç¶ããŠãã«ãŒãå
¥åã«ã¡ãã»ãŒãžã1åéä¿¡ããŸãã ãªããªã ã¿ã€ããŒã¯ç©ºã®ã¡ãã»ãŒãžãã«ãŒãå
¥åã«éä¿¡ããŸãããããäœãã§åããå¿
èŠããããŸã-ã¡ãã»ãŒãžæ¬æã«ãHello worldã <setBody>ãšããããã¹ããå
¥ããŸãã ã«ãŒãã®æåŸã§ãã¡ãã»ãŒãžæ¬æã®å
容ããã°<log message = "$ {body}">ã«è¡šç€ºããŸãã
- ãããžã§ã¯ãããŸãšãã ïŒ mvnããã±ãŒãž
- å±éããããã³ãã«ã
ServiceMixã§ãã³ãã«ãå±éãã1ã€ã®æ¹æ³ã¯ãjarãã¡ã€ã«ãdeployãã£ã¬ã¯ããªã«ã³ããŒããããšã§ãã çµã¿ç«ãŠãjarãServiceMix / deployãã£ã¬ã¯ããªã«ã³ããŒããŸãã
ServiceMixãã°ãèŠãŠãã ããïŒ
ServiceMix / data / log / servicemix.log æ°ãããã³ãã«ãã€ã³ã¹ããŒã«ããŠèµ·åããæ
å ±ã«å ããŠããHello worldããšããç¢æã衚瀺ãããŸãã
HelloWorldRoute | 43-org.apache.camel.camel-core-2.16.3 | ãããŒã¯ãŒã«ãsshã³ã³ãœãŒã«ã«ãã°ã€ã³ããŠãã³ã³ããã¹ããªã¹ãã³ã³ããã¹ãã®ãã£ã¡ã«ãªã¹ããšã«ãŒããªã¹ãã«ãŒãã®ãªã¹ãã衚瀺ããŠã¿ãŠãã ããã ã³ãã³ãã®åºåã«ã¯ãHelloWorldContextãšHelloWorldRouteããããŸãã
çµè«
çµè«ãšããŠãServiceMixãšCamelã¯çµ±åãœãªã¥ãŒã·ã§ã³ãæ§ç¯ããããã®åªãã補åã§ãããšèšããããšæããŸãã ã»ãšãã©ãã¹ãŠã®ã¿ã¹ã¯ã§ããšã¬ã¬ã³ãã§ã·ã³ãã«ãªãœãªã¥ãŒã·ã§ã³ãèŠã€ãããŸãã 補åã¯éåžžã«ããèããããŠãããéçºè
ã¯æ¬åœã«äžçæžåœåããŠããããšãããããŸãã åœç€Ÿã®ServiceMixã¯2幎é䜿çšãããŠãããçŸæç¹ã§ã¯çŽ16ã®æ
å ±ã·ã¹ãã ãçµ±åãã150以äžã®çµ±åãµãŒãã¹ãéçºããŠããŸãã äžéšã®ã³ã³ããŒãã³ãã«ã¯ãŸã åé¡ããããŸããããåžžã«åæ§ã®ã³ã³ããŒãã³ãããããããããéžæãããã極端ãªå Žåã«ã¯ç¬èªã®ã³ã³ããŒãã³ããéçºãããã§ããŸãã äžè¬çã«ã補åã¯å®å®ããŠç¢ºå®ã«åäœããŸããå人çã«ã¯ãç§ã®å°è±¡ã¯æãããžãã£ãã§ãã çŽãããªãå©ç¹ã¯ããœãŒã¹ã³ãŒãã®ãªãŒãã³æ§ãšã©ã€ã»ã³ã¹ã賌å
¥ããå¿
èŠããªãããšã§ãã ããã«ããããã®è£œåã¯ãåæ¥çãªåçåãã絶察ã«å£ã£ãŠããŸããã ãŸããServiceMixãšCamelã¯ãçµ±åã®åé¡ã解決ããããã ãã§ãªã䜿çšã§ããããšã«ã泚æããŠãã ããã ããšãã°ãKarafã¯Webã¢ããªã±ãŒã·ã§ã³ãå±éããã®ã«æé©ã§ãã ãã®æ©äŒãå©çšããŠã管çè
ãçµ±åãã©ãããã©ãŒã ãæ§æããããã®Webã€ã³ã¿ãŒãã§ã€ã¹ãæäŸããŸãã Camelã¯ãããŸããŸãªããžãã¹ã³ã³ããŒãã³ããšã·ãŒã ã¬ã¹ã«çµ±åããŸãã ããšãã°ãDroolsïŒããžãã¹ã«ãŒã«ãšã³ãžã³ïŒã䜿çšããŠãç¹å®ã®ã«ãŒã«ïŒããŒããã©ãªãªã䜿çšãããã©ã³ã¶ã¯ã·ã§ã³åŒ·åïŒã«åŸã£ãŠçä¿¡ãã©ã³ã¶ã¯ã·ã§ã³ãé©åãªããŒããã©ãªãªã«å²ãåœãŠãŸããããã¯ããã«ãªãã£ã¹ã®ãŠãŒã¶ãŒã«ãã£ãŠæ§æãããŸãã éåžžã«èå³æ·±ã補åã¯ActivitiïŒBPMãšã³ãžã³ïŒã§ããããã¯Karafã³ã³ãããŒã§åäœããCamelãšçµ±åã§ããŸãã ããã«ãããçµ±åãšããžãã¹æ©èœãçµã¿åãããéåžžã«èå³æ·±ããœãªã¥ãŒã·ã§ã³ãäœæã§ããŸãã