|
1. ¼ò½é
Mule ESBÊÇÒ»¸ö»ùÓÚJavaµÄÇáÁ¿¼¶ÆóÒµ·þÎñ×ÜÏߺͼ¯³Éƽ̨£¬ÔÊÐí¿ª·¢ÈËÔ±¿ìËÙ±ãÀûµØÁ¬½Ó¶à¸öÓ¦Ó㬲¢Ö§³ÖÓ¦ÓüäµÄÊý¾Ý½»»»¡£Mule
ESBÖ§³Ö¼¯³ÉÏÖÓÐϵͳ¶øÎÞÂÛÆäµ×²ã²ÉÓúÎÖÖ¼¼Êõ£¬ÈçJMS¡¢Web Services¡¢JDBC¡¢HTTPÒÔ¼°ÆäËû¼¼Êõ¡£
2. ÕûÌå½á¹¹

ͼ ÕûÌå½á¹¹
´ÓÉÏͼ¿É¼û£¬Muleͨ¹ýTransports/ConnectorsÓëÍâΧµÄÒ칹ϵͳÁ¬½Ó£¬ÌṩRouting£¨Â·ÓÉ£©¡¢Transaction
Management£¨ÊÂÎñ¹ÜÀí£©¡¢Transformation£¨×ª»»£©¡¢Message Broker£¨ÏûÏ¢´úÀí£©¡¢Transportation
Management£¨´«Êä¹ÜÀí£©¡¢Security£¨°²È«£©µÈºËÐÄÄ£¿é¡£Mule¿ÉÒÔµ¥¶ÀʹÓã¬Ò²¿ÉÒÔ¼ÜÉèÔÚ³£ÓõÄÓ¦Ó÷þÎñÆ÷ÉÏ¡£

ͼ ¼Ü¹¹¼òͼ
ÍâΧϵͳµÄ·þÎñÇëÇóͨ¹ýMule ESBµÄTransport½ÓÈ룬Muleͨ¹ýTransformer½øÐÐÊý¾ÝµÄ¸ñʽת»»£¬È»ºó¾¹ýInbound
Router½øÐÐÏûÏ¢¹ýÂË£¨ÄÚ²¿Í¨¹ýÅäÖÃfilterʵÏÖ£©ºó½»¸øMuleµÄComponent½øÐÐÒµÎñÂß¼´¦Àí£¬´¦ÀíºóµÄ½á¹ûͨ¹ýOutbound
RouterÈ·¶¨´«µÝ¸øÄĸö½ÓÊÕ·½£¬È»ºóͨ¹ýTransformer½øÐÐÊý¾Ý¸ñʽת»»£¬Í¨¹ýTransportÁ¬½ÓÖÁ½ÓÊÕ·½£¬´«µÝÐÅÏ¢¡£
´ËͼÃèÊöµÄÊÇMuleÖеÄÒ»¸öµäÐͳ¡¾°µÄ´¦Àí¹ý³Ì£¬º¸ÇÁËMuleÖеĸ÷¸ö¹Ø¼ü×é¼þ¡£ÆäÖÐijЩ´¦Àí²½Öè²»ÊDZØÐëµÄ£¬ÈçInbound
Router¡¢Transformer¡£ºóÐø¿ÉÒÔ¿´µ½Ò»Ð©ÆäËû³¡¾°µÄ´¦Àí¡£
3. ¹¦ÄÜ
a. ·þÎñÖнé
½«ÒµÎñÂß¼ºÍÏûÏ¢·¢ËÍ·ÖÀë
ÆÁ±Î·þÎñµÄÏûÏ¢¸ñʽºÍÐÒé
ÌṩÈÎÒâλÖõķþÎñµ÷ÓÃ
ÌṩÐÒéÇŽÓ
b. Êý¾Ýת»»
ÔÚÓ¦Óü佻»»²»Í¬¸ñʽµÄÐÅÏ¢
²Ù×÷ÏûÏ¢µÄ¸ºÔØÄÚÈÝ£¬°üÀ¨¼ÓÃÜ¡¢Ñ¹ËõºÍ±àÂëת»»
ÔÚÒì¹¹µÄ´«ÊäÐÒéµÄÊý¾ÝÀàÐͼä¸ñʽ»¯ÏûÏ¢
c. ÏûϢ·ÓÉ
»ùÓÚÏûÏ¢ÄÚÈݺ͸´ÔÓ¹æÔò·ÓÉÏûÏ¢
ÏûÏ¢µÄ¹ýÂË¡¢¾ÛºÏÒÔ¼°ÖØÐÂÅÅÁÐÐòºÅ
d. ·þÎñ´´½¨ºÍÍйÜ
±©Â¶¶Ëµã¡¢EJB¡¢Spring BeanÒÔ¼°POJO×÷Ϊ·þÎñ
×÷ΪÇáÁ¿¼¶µÄ·þÎñÈÝÆ÷½øÐзþÎñÍйÜ
Mule ESBÖÐÓÐһЩ»ù±¾µÄ¸ÅÄÀí½âÕâЩ»ù±¾¸ÅÄîºó²ÅÄÜÀí½âMuleµÄÄÚ²¿»úÖÆ¡£´ÓÖÐÒ²¿ÉÒÔ¿´µ½Mule½â¾öÎÊÌâµÄ»ù±¾Ë¼Â·¡£
4. »ù±¾¸ÅÄî
4.1 Model
Model±íʾÍйܸ÷¸ö·þÎñµÄÔËÐÐʱ»·¾³¡£

ͼ Model
4.2 Service
ServiceÊÇÓÃÀ´´¦Àí·þÎñÇëÇóµÄ»ù±¾µ¥Î»£¬Ëüµ÷Óø÷¸ö×é¼þ½øÐзþÎñÇëÇóµÄ´¦Àí¡£

ͼ Service
4.3 Transport
Transport¹ÜÀíÏûÏ¢µÄ½ÓÊպͷ¢ËÍ£¬Êý¾Ýת»»µÄ¹ý³ÌÒ²ÊÇÔÚTransportÖÐͨ¹ýµ÷ÓÃTransformerÍê³ÉµÄ¡£

ͼ Transport
4.3.1 Connector
ConnectorÓÃÓڹܿØÌض¨ÐÒéµÄʹÓã¬ÈçHTTP Connector¡¢JMS ConnectorµÈ¡£
4.3.2 End-Point
EndpointÓÃÓÚ±íʾһÖÖÐÒéµÄÌØ¶¨Ê¹Ó÷½Ê½£¬Èçlistening/polling¡¢´ÓÖжÁÈ¡¡¢ÏòÖ¸¶¨µØÖ·Ð´ÈëµÈ£¬¶¨ÒåÁË·¢ËͺͽÓÊÕÏûÏ¢µÄͨµÀ¡£Endpoint¿ØÖƵÄÊǵײãµÄʵÌåÔÚConnectorÖÐÈçºÎ±»Ê¹Óá£
Endpoint¶¨ÒåÓÚInboundºÍOutbound RouterÖС£
4.4 Transformer
TransformerÓÃÓÚת»»ÏûÏ¢µÄÄÚÈÝ¡£

ͼ Transformer
4.5 Router
RouterʹÓÃFilter»ùÓÚÏûÏ¢ÖеÄÊôÐÔÐÅÏ¢½øÐÐÏûÏ¢µÄ·Ö·¢¡£

ͼ Router
RouterÔÚServiceÖеÄλÖþö¶¨ÁËRouterµÄÐÔÖÊ£¨inbound¡¢outboundºÍresponse£©ºÍµ£ÈεĽÇÉ«£¨pass-through¡¢aggregatorµÈ£©¡£
4.6 Component
ComponentÊÇServiceµÄºËÐIJ¿¼þ£¬ÊÇServiceµÄÒµÎñÂß¼µÄʵÏÖ¡£

ͼ Component: implicit
bridge component
Component¿ÉÒÔÊÇJava Class£¨POJO¡¢Spring Bean£©¡¢Web Service¡¢ScriptµÈ¡£
Component¿É¶¨Òå×Ô¼ºµÄÉúÃüÖÜÆÚ£ºinitialise¡¢start¡¢stop¡¢dispose£¬²»¹ýÐèҪʵÏÖMuleµÄLifeCycle½Ó¿Ú¡£Mule
3.0°æ±¾¿ªÊ¼Ìṩ@PostConstructºÍ@PreDestroyµÄ×¢½â£¬¶ÔÓ¦ÉúÃüÖÜÆÚµÄinitialiseºÍdispose½×¶Î£¬²»ÐèҪʵÏÖMuleµÄLifeCycle½Ó¿ÚÁË¡£
4.7 Flow£¨@since 3.0£©
FlowÊÇMule 3.0ÐÂÒýÈëµÄ£¬°üº¬Ò»¸öÏûÏ¢Ô´£¨Message Source£©ºÍ¶à¸öÏûÏ¢´¦ÀíÆ÷×é³ÉµÄ´¦ÀíÆ÷Á´¡£

ͼ Flow
¸ù¾Ýʵ¼ÊÐèÇó×ÅÖØ¼ì²éÁËÒ»ÏÂMule ESBµÄÏûÏ¢´«µÝ·½Ê½¡£MuleÖ§³Ö³£Óõļ¸ÖÖÏûÏ¢´«µÝ·½Ê½£¬Äܹ»Âú×ãÒªÇó¡£
5. ÏûÏ¢´«µÝ·½Ê½
5.1 Òì²½·½Ê½
Òì²½·½Ê½ÊÇÒ»ÖÖµ¥Ïòµ÷Ó㬵÷ÓÃÕß²»ÐèÒª»ñµÃÏìÓ¦¡£

ͼ Asynchronous
Òì²½·½Ê½Í¨¹ýinboundºÍoutbound endpointµÄexchange-pattern=¡±one-way¡±ÊµÏÖ¡£
ʹÓûù±¾µÄStdio TransportÑéÖ¤£¬Í¨¹ý±ê×¼ÊäÈë´«Êä×Ö·û´®£¬½«ÆäÔÑù´«µÝ¸ø±ê×¼Êä³ö½øÐÐÏÔʾ¡£ÏàÓ¦ÅäÖÃÈçÏ£º
<service name="echo"> <inbound> <stdio:inbound-endpoint system="IN" exchange-pattern="one-way" /> </inbound> <component> <singleton-object class="demo.mule.umo.StdIo" /> </component> <outbound> <pass-through-router> <stdio:outbound-endpoint system="OUT" exchange-pattern="one-way" /> </pass-through-router> </outbound> </service> |
ÔËÐзþÎñ£¬¿ØÖÆÌ¨ÏÔʾ½á¹ûÈçÏ£º
Please enter: Hello, world! INFO 2010-12-07 19:21:18,877 [ConsoleConnector.dispatcher.1] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'ConsoleConnector.dispatcher.23255376'. Object is: StdioMessageDispatcher INFO 2010-12-07 19:21:18,877 [ConsoleConnector.dispatcher.1] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'ConsoleConnector.dispatcher.23255376'. Object is: StdioMessageDispatcher Hello, world! |
ÆäÖÐINFOÊä³öÊÇMuleµÚÒ»´Î³õʼ»¯ÏàÓ¦Connector´òÓ¡³öÀ´µÄ£¬Ö®ºóµ÷Ó÷þÎñ²»»áÔÙ´ÎÏÔʾ¡£
Òì²½·½Ê½ÊÊÓÃÓÚ¼òµ¥µÄÏûÏ¢´«µÝµÄ³¡¾°¡£
5.2 ÇëÇó-ÏìÓ¦·½Ê½
ÇëÇó-ÏìÓ¦·½Ê½¼´ÇëÇó·½µ÷Ó÷þÎñºó£¬·þÎñÁ¢¼´´¦Àí²¢·µ»ØÏìÓ¦½á¹û£¬²»Ð轫ÏûÏ¢Ôٴδ«µÝ¡£

ͼ Request-Response
ÇëÇó-ÏìÓ¦·½Ê½Í¨¹ýinput endpointµÄexchange-pattern=¡±request-response¡±ÊµÏÖ£¬ÏàÓ¦ÅäÖÃÈçÏ£º
<strong> <strong> <model name="services"> <service name="echoService"> <inbound> <inbound-endpoint address="http://localhost:7007/services/Echo" exchange-pattern="request-response"> <cxf:jaxws-service /> </inbound-endpoint> </inbound> <component> <singleton-object class="demo.mule.umo.Echo" /> </component> </service> </model> </strong> </strong> |
ÉϱßÊÇͨ¹ýserviceÅäÖõģ¬Í¨¹ýflowÅäÖÃÈçÏ£º
<flow name="EchoFlow"> <inbound-endpoint address="http://localhost:7007/services/Echo" exchange-pattern="request-response" /> <cxf:jaxws-service serviceClass="demo.mule.umo.Echo" /> <component> <singleton-object class="demo.mule.umo.Echo" /> </component> </flow> |
ÔÚä¯ÀÀÆ÷ÖÐÊäÈë¡°http://localhost:7007/services/Echo/echo/text/hello,world¡±£¬ä¯ÀÀÆ÷ÖлáÏÔʾ¡°hello,world¡±µÄÊä³öÐÅÏ¢¡£
ÇëÇó-ÏìÓ¦·½Ê½ÊÊÓÃÓÚµ¥´Î·þÎñµ÷Óõij¡¾°¡£
5.3 ͬ²½·½Ê½
ͬ²½·½Ê½¼´ÇëÇó·½µ÷Ó÷þÎñºó£¬component½«´¦Àí½á¹û·¢Ë͸øÁíÒ»¸öÍⲿ·þÎñ´¦Àí£¬²¢½«´¦Àí½á¹û·´·½Ïò·µ»Ø¡£

ͼ Synchronous
ͬ²½·½Ê½Í¨¹ýinboundºÍoutbound endpointµÄexchange-pattern=¡±request-response¡±ÊµÏÖ£¬ÏàÓ¦ÅäÖÃÈçÏ£º
<flow name="echo"> <inbound-endpoint address="http://localhost:7007/services/Echo" exchange-pattern="request-response" /> <cxf:jaxws-service serviceClass="demo.mule.umo.Echo" /> <component> <singleton-object class="demo.mule.umo.StdIo" /> </component> <vm:outbound-endpoint path="vm" exchange-pattern="request-response" /> </flow> <flow name="vm"> <vm:inbound-endpoint path="vm" exchange-pattern="request-response" /> <component> <singleton-object class="demo.mule.umo.Vm" /> </component> <stdio:outbound-endpoint system="OUT" exchange-pattern="one-way" /> </flow> |
ͬ²½·½Ê½ÊÊÓÃÓÚͨ¹ýMuleµ÷ÓÃÔ¶³Ì·þÎñµÄ³¡¾°¡£
5.4 Òì²½ÇëÇó-ÏìÓ¦·½Ê½
Òì²½ÇëÇó-ÏìÓ¦·½Ê½¼´ÇëÇó·½µ÷Ó÷þÎñºó²»ÐèÒªÁ¢¼´»ñµÃ·µ»Ø½á¹û£¬component½«ÇëÇó·¢Ë͸øÆäËûÍâΧϵͳ´¦Àí£¨¿ÉÄÜÓжà¸ö£©£¬È«²¿´¦ÀíÍê±Ïºóͨ¹ýÖ¸¶¨µÄÒì²½Ó¦´ðRouter·µ»Ø¸øÇëÇ󷽡£

ͼ Asynchronous Request-Response
Òì²½ÇëÇó-ÏìÓ¦·½Ê½Í¨¹ýÔÚOutBound EndpointÖÐÔö¼Óreply-toÒÔ¼°Ôö¼Óasync-reply½ÚµãʵÏÖ£¬ÏìÓ¦ÅäÖÃÈçÏ£º
<flow name="echo"> <inbound-endpoint address="http://localhost:7007/services/Echo" exchange-pattern="request-response" /> <cxf:jaxws-service serviceClass="demo.mule.umo.Echo" /> <component> <singleton-object class="demo.mule.umo.StdIo" /> </component> <vm:outbound-endpoint path="vm" exchange-pattern="request-response" /> </flow> <flow name="vm"> <vm:inbound-endpoint path="vm" exchange-pattern="request-response" /> <component> <singleton-object class="demo.mule.umo.Vm" /> </component> <stdio:outbound-endpoint system="OUT" exchange-pattern="one-way" /> </flow> |
Òì²½ÇëÇó-ÏìÓ¦·½Ê½ÊÊÓÃÓÚÇëÇóÐèÒª±»¶à¸öÔ¶³Ì·þÎñ²¢Ðд¦Àí£¬½á¹ûÐèÒª»ã×Ü´¦Àíºó·µ»ØµÄ³¡¾°¡£
×¢£ºÉÏÊö´úÂëδÔËÐÐͨ¹ý£¬queue1ºÍqueue2»ñµÃÁËÇëÇóÏûÏ¢²¢Õý³£´¦Àí£¬µ«·µ»ØÖÁasync-replyʱÅ׳öÒì³££¬ÔÝδ¶¨Î»µ½ÎÊÌâ¡£
ºó½«collection-async-reply-router¸ÄΪsingle-async-reply-router䱨Òì³££¬´úÂëʾÀýÈçÏ£º
<em><service name="async req-rep"> <inbound> <stdio:inbound-endpoint ref="stdioInEndpoint" /> </inbound> <component class="demo.mule.umo.Echo" /> <outbound> <multicasting-router> <vm:outbound-endpoint path="async.queue1" exchange-pattern="one-way" /> <vm:outbound-endpoint path="async.queue2" exchange-pattern="one-way" /> <reply-to address="vm://reply" /> </multicasting-router> </outbound> <async-reply timeout="5000" failOnTimeout="true"> <vm:inbound-endpoint path="reply" exchange-pattern="one-way" /> <single-async-reply-router /> </async-reply> </service></em> |
µÈÓпտ´¿´collection-async-reply-router°É£¬»òÕß×Ô¶¨Òårouter¡£
|