前言
發現JBossESB網上流傳甚廣的就是JBoss學習筆記系列了,這個系列資料還可以,但如果你一上來就看這個的話,感覺還是有點蒙,因爲根本不明白這樣做到底是爲什麼。所以看了之後,也會發現自己只能照着葫蘆畫一個葫蘆,連一個瓢也畫不了。
helloworld這句話從我們一進行編程的世界就經常聽到,那麼第一個例子,我們就來helloworld。
ESB目錄結構
ESB發佈之後,會是一個.esb格式的zip壓縮包,裏面的結構如下:
其中:
jboss-esb.xml:包含service、listener、action、provider的配置,具體都是什麼,後面會說到的。
deployment.xml:是可選的,有兩種情況下會用這個。一種是一個.esb依賴令一個.esb,用來指定加載順序,另一種就是確定.esb的部署範圍。不明白沒關係,有的是例子使你明白這個的用處的。
java classes:是你自己的包含包層次的action
jars:這個我想不用說吧,就是添加你的應用依賴的包
queue-service.xml:如果你的jboss-esb.xml中的provider使用的queue或者topic,你可以在通過這個來進行部署。使用其它方式督署也可以,不過ESB的官方文檔中明確說明的建議採取此種方式。
運行helloworld
helloworld配置解析
public class MyJMSListenerAction extends AbstractActionLifecycle
{
protected ConfigTree _config;
public MyJMSListenerAction(ConfigTree config) { _config = config; }
public Message displayMessage(Message message) throws Exception{
System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
System.out.println("Body: " + message.getBody().get()) ;
System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
return message;
}
}
怎樣寫Action,自己查文檔吧,沒啥意思。jboss-esb.xml
<?xml version = "1.0" encoding = "UTF-8"?>
<jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd" parameterReloadSecs="5">
<providers>
<jms-provider name="JBossMQ" connection-factory="ConnectionFactory">
<jms-bus busid="quickstartGwChannel">
<jms-message-filter
dest-type="QUEUE"
dest-name="queue/quickstart_helloworld_Request_gw"
/>
</jms-bus>
<jms-bus busid="quickstartEsbChannel">
<jms-message-filter
dest-type="QUEUE"
dest-name="queue/quickstart_helloworld_Request_esb"
/>
</jms-bus>
</jms-provider>
</providers>
<services>
<service
category="FirstServiceESB"
name="SimpleListener"
description="Hello World">
<listeners>
<jms-listener name="JMS-Gateway"
busidref="quickstartGwChannel"
is-gateway="true"
/>
<jms-listener name="helloWorld"
busidref="quickstartEsbChannel"
/>
</listeners>
<actions mep="OneWay">
<action name="action1"
class="org.jboss.soa.esb.samples.quickstart.helloworld.MyJMSListenerAction"
process="displayMessage"
/>
<action name="action2" class="org.jboss.soa.esb.actions.SystemPrintln">
<property name="printfull" value="false"/>
</action>
<!-- The next action is for Continuous Integration testing -->
<action name="testStore" class="org.jboss.soa.esb.actions.TestMessageStore"/>
</actions>
</service>
</services>
</jbossesb>
jbm-queue-service.xml
<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.jms.server.destination.QueueService"
name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb"
xmbean-dd="xmdesc/Queue-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
</mbean>
<mbean code="org.jboss.jms.server.destination.QueueService"
name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_gw"
xmbean-dd="xmdesc/Queue-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
</mbean>
</server
如果你看sample/quickstart/helloworld下面,還有一個jbmq-queue-service.xml,但部署文件裏只有jbm-queue-service.xml。
<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.mq.server.jmx.Queue"
name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb">
<depends optional-attribute-name="DestinationManager">
jboss.mq:service=DestinationManager
</depends>
</mbean>
<mbean code="org.jboss.mq.server.jmx.Queue"
name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_gw">
<depends optional-attribute-name="DestinationManager">
jboss.mq:service=DestinationManager
</depends>
</mbean>
</server>
jbm-queue-service.xml是JBoss messaging這種消息使用方式採用的配置文件,jbmq-queue-service.xml是JBossMQ的配置文件,但官方建議我們使用JBoss messaging,具體原因還待日後研究,只能說時間和精力有限啊。。。
deployment.xml
<jbossesb-deployment>
<depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb</depends>
<depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_gw</depends>
</jbossesb-deployment>
上面說過兩種情況你會用到這個東西,esb部署上來需要使用到QUEUE或Topic,也就是說QUEUE這些東西是需要在程序部署上來之前就創建好。我感覺這個只是說明一下順序,而創建工作是jbm-queue-service.xml這個配置文件中做的事情。