我最近加入了一个新任务,在该任务中,我们必须基于WSO2工具栈实施ESB解决方案。 尽管我熟悉ESB的大多数概念以及其他一些实现(例如Mule ESB ),但这是我第一次必须使用WSO2 ESB 。 幸运的是,可以找到很多文档 ,并且该工具附带了大量示例,介绍如何使用ESB。 在这篇文章中,我展示了使第一个示例正常工作的步骤。 有关更详尽的说明,请参见此处的信息。
第一步是下载并安装ESB,这确实很容易。 您可以在此处下载zip。 下载后,只需将其解压缩到要安装该工具的位置即可。 我安装在目录中
'用户/pascal/develop/wso2esb-4.5.1? 解压缩后,您将在解压缩的文件夹中看到文件“ INSTALL.txt”。 在此文件中,所有信息都说明了如何启动和停止ESB。 要使用样本,您必须使用以下命令启动ESB:
./wso2esb-samples.sh -sn ${sample-number}
其中“ $ {sample-number}”是您要运行的样品编号。 因此,要使用示例1运行ESB,只需使用以下命令启动ESB:
'./wso2esb-samples.sh -sn 1'
并且您将看到这样的日志记录:
请注意,通过修改目录“ $ CARBON_HOME / repository / conf /”中的“ log4j.properties”,我将“ org.apache.synapse”包的日志级别设置为DEBUG。 第一个示例主要基于代理或重定向到现有服务。 这些服务基于Axis2,并且随WSO2 ESB的安装一起提供。 要启动Axis2服务器,请打开一个新的终端窗口,浏览至目录'$ CARBON_HOME / samples / axis2Server',然后执行命令'./axis2server.sh'。 如在日志记录的控制台中所示,这将启动SimpleAxisServer:
如果打开浏览器并导航到'http://localhost:9000/services'
,将会看到我们当前没有正在运行的服务:
要部署服务,例如SimpleStockQuoteService,请打开一个新终端并导航到以下目录:$ CARBON + HOME / samples / axis2Server / src / SimpleStockQuoteService。 在这里,只需提供“ ant”命令,即可将服务编译,构建并部署到我们之前启动的Axis2Server:
现在,如果我们查看'http://localhost:9000/services'
我们将看到SimpleStockService可用于请求:
如果需要,可以使用SoapUI测试服务:
因此,现在我们已经为第一个示例准备好了服务器端。 让我们运行客户端。 每个样本都有说明如何运行Axis2客户端的文档。 对于样本1,文档显示如下:
打开一个新终端,浏览到以下目录“ /Users/pascal/develop/wso2esb-4.5.1/samples/axis2Client”,并提供所述命令以运行客户端:
如您所见,我们收到了IBM股票的报价。 在运行WSO2 ESB的终端中,我们看到由传入请求引起的以下日志记录:
[2013-03-03 16:58:03,113] DEBUG - SynapseMessageReceiver Synapse received a new message for message mediation...
[2013-03-03 16:58:03,114] DEBUG - SynapseMessageReceiver Received To: /services/StockQuote
[2013-03-03 16:58:03,114] DEBUG - SynapseMessageReceiver SOAPAction: urn:getQuote
[2013-03-03 16:58:03,114] DEBUG - SynapseMessageReceiver WSA-Action: urn:getQuote
[2013-03-03 16:58:03,114] DEBUG - Axis2SynapseEnvironment Injecting MessageContext
[2013-03-03 16:58:03,115] DEBUG - Axis2SynapseEnvironment Using Main Sequence for injected message
[2013-03-03 16:58:03,115] DEBUG - SequenceMediator Start : Sequence <main>
[2013-03-03 16:58:03,115] DEBUG - SequenceMediator Sequence <SequenceMediator> :: mediate()
[2013-03-03 16:58:03,115] DEBUG - InMediator Start : In mediator
[2013-03-03 16:58:03,115] DEBUG - InMediator Current message is incoming - executing child mediators
[2013-03-03 16:58:03,115] DEBUG - InMediator Sequence <InMediator> :: mediate()
[2013-03-03 16:58:03,115] DEBUG - FilterMediator Start : Filter mediator
[2013-03-03 16:58:03,116] DEBUG - FilterMediator Source : get-property('To') against : .*/StockQuote.* matches - executing child mediators
[2013-03-03 16:58:03,116] DEBUG - FilterMediator Sequence <FilterMediator> :: mediate()
[2013-03-03 16:58:03,116] DEBUG - SendMediator Start : Send mediator
[2013-03-03 16:58:03,116] DEBUG - EndpointContext Checking if endpoint : endpoint_d06dafda969c8e11992a8e8f5366fd33203399eaae89984c currently at state ACTIVE can be used now?
[2013-03-03 16:58:03,116] DEBUG - AddressEndpoint Sending message through endpoint : endpoint_d06dafda969c8e11992a8e8f5366fd33203399eaae89984c resolving to address = http://localhost:9000/services/SimpleStockQuoteService
[2013-03-03 16:58:03,116] DEBUG - AddressEndpoint SOAPAction: urn:getQuote
[2013-03-03 16:58:03,116] DEBUG - AddressEndpoint WSA-Action: urn:getQuote
[2013-03-03 16:58:03,117] DEBUG - Axis2FlexibleMEPClient Sending [add = false] [sec = false] [rm = false] [mtom = false] [swa = false] [format = null] [force soap11=false] [force soap12=false] [pox=false] [get=false] [encoding=null] [to=http://localhost:9000/services/SimpleStockQuoteService]
[2013-03-03 16:58:03,117] DEBUG - Axis2FlexibleMEPClient Message [Original Request Message ID : urn:uuid:381071f8-c6ca-4e14-bfe4-0e53de7f7cc2] [New Cloned Request Message ID : urn:uuid:503aabca-2a04-413f-ba44-b6c623bf9db6]
[2013-03-03 16:58:03,117] DEBUG - SynapseCallbackReceiver Callback added. Total callbacks waiting for : 1
[2013-03-03 16:58:03,119] DEBUG - SendMediator End : Send mediator
[2013-03-03 16:58:03,120] DEBUG - DropMediator Start : Drop mediator
[2013-03-03 16:58:03,120] DEBUG - DropMediator End : Drop mediator
[2013-03-03 16:58:03,120] DEBUG - FilterMediator End : Filter mediator
[2013-03-03 16:58:03,120] DEBUG - InMediator End : In mediator
[2013-03-03 16:58:03,120] DEBUG - SequenceMediator End : Sequence <main>
[2013-03-03 16:58:03,130] DEBUG - SynapseCallbackReceiver Callback removed for request message id : urn:uuid:503aabca-2a04-413f-ba44-b6c623bf9db6. Pending callbacks count : 0
[2013-03-03 16:58:03,132] DEBUG - SynapseCallbackReceiver Synapse received an asynchronous response message
[2013-03-03 16:58:03,133] DEBUG - SynapseCallbackReceiver Received To: null
[2013-03-03 16:58:03,133] DEBUG - SynapseCallbackReceiver SOAPAction:
[2013-03-03 16:58:03,133] DEBUG - SynapseCallbackReceiver WSA-Action:
[2013-03-03 16:58:03,134] DEBUG - SynapseCallbackReceiver Body :
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'><soapenv:Body><ns:getQuoteResponse xmlns:ns='http://services.samples'><ns:return xmlns:ax21='http://services.samples/xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='ax21:GetQuoteResponse'><ax21:change>4.155006565416989</ax21:change><ax21:earnings>-8.118428276798063</ax21:earnings><ax21:high>84.31871512134151</ax21:high><ax21:last>80.49639852693167</ax21:last><ax21:lastTradeTimestamp>Sun Mar 03 16:58:03 CET 2013</ax21:lastTradeTimestamp><ax21:low>-79.94179251359746</ax21:low><ax21:marketCap>-6855110.427635921</ax21:marketCap><ax21:name>IBM Company</ax21:name><ax21:open>83.68193468970854</ax21:open><ax21:peRatio>23.68015151185118</ax21:peRatio><ax21:percentageChange>-5.440098733913549</ax21:percentageChange><ax21:prevClose>-76.37741093768571</ax21:prevClose><ax21:symbol>IBM</ax21:symbol><ax21:volume>16034</ax21:volume></ns:return></ns:getQuoteResponse></soapenv:Body></soapenv:Envelope>
[2013-03-03 16:58:03,134] DEBUG - Axis2SynapseEnvironment Injecting MessageContext
[2013-03-03 16:58:03,135] DEBUG - Axis2SynapseEnvironment Using Main Sequence for injected message
[2013-03-03 16:58:03,135] DEBUG - SequenceMediator Start : Sequence <main>
[2013-03-03 16:58:03,135] DEBUG - SequenceMediator Sequence <SequenceMediator> :: mediate()
[2013-03-03 16:58:03,135] DEBUG - InMediator Start : In mediator
[2013-03-03 16:58:03,135] DEBUG - InMediator Current message is a response - skipping child mediators
[2013-03-03 16:58:03,135] DEBUG - InMediator End : In mediator
[2013-03-03 16:58:03,135] DEBUG - OutMediator Start : Out mediator
[2013-03-03 16:58:03,136] DEBUG - OutMediator Current message is outgoing - executing child mediators
[2013-03-03 16:58:03,136] DEBUG - OutMediator Sequence <OutMediator> :: mediate()
[2013-03-03 16:58:03,136] DEBUG - SendMediator Start : Send mediator
[2013-03-03 16:58:03,136] DEBUG - SendMediator Sending response message using implicit message properties..
Sending To: http://www.w3.org/2005/08/addressing/anonymous
SOAPAction:
[2013-03-03 16:58:03,138] DEBUG - SendMediator End : Send mediator
[2013-03-03 16:58:03,138] DEBUG - OutMediator End : Out mediator
[2013-03-03 16:58:03,138] DEBUG - SequenceMediator End : Sequence <main>
最后,在Axis2Server终端中,由于示例流将请求传递到端口9000,因此将以下行添加到日志记录中:
Sun Mar 03 16:58:03 CET 2013 samples.services.SimpleStockQuoteService :: Generating quote for : IBM
这表明该示例运行正常,并且已执行所有预期的操作。 下一步将通过所有其他示例,以更好地理解WSO2 ESB的可能性。
参考: 从WSO2 ESB开始,在The Pragmatic Integrator博客上运行我们的JCG合作伙伴 Pascal Alma 的示例 。
翻译自: https://www.javacodegeeks.com/2013/03/starting-with-wso2-esb-by-running-the-samples.html