我正在使用Spring集成來解析XML文件,我需要爲每個標記創建一個線程(並且每個都有不同的速率)。彈簧集成 - 從配置文件調度作業
現在(在這裏的許多用戶:)的幫助下)我能夠通過標記拆分XML,然後將其路由到合適的service-activator
。
這很好,但我無法重定向到創建「一個線程」,然後執行操作的通道。現在,我有以下的配置,並在我的心(我不知道它是否是正確的......)
Split tag -> Route to the appropiate channel -> Start a thread(from tag configuration) -> Execute the operation
這是我的實際配置是分裂標記並重定向到該通道。 路由器不應直接重定向到頻道,而是安排它們。
在第一個例子中,我們可以將它重定向到固定速率的池中,稍後我將使用XPATH獲取屬性,然後用正確的值替換這個「固定」速率。
我已經嘗試了許多解決方案來創建這個流程,但是每一個失敗或不進行編譯:(
<context:component-scan base-package="it.mypkg" />
<si:channel id="rootChannel" />
<si-xml:xpath-splitter id="mySplitter" input-channel="rootChannel" output-channel="routerChannel" create-documents="true">
<si-xml:xpath-expression expression="//service" />
</si-xml:xpath-splitter>
<si-xml:xpath-router id="router" input-channel="routerChannel" evaluate-as-string="true">
<si-xml:xpath-expression expression="concat(name(./node()), 'Channel')" />
</si-xml:xpath-router>
<si:service-activator input-channel="serviceChannel" output-channel="endChannel">
<bean class="it.mypkg.Service" />
</si:service-activator>
UPDATE: 使用這種配置的service
這應該運行任務每10秒(該id=service1
),並每5秒另一個(id=service2
)。以同樣的方式,我可以有一個由另一個類處理(因爲這將有另一個行爲),另一個標籤
<root>
<service id="service1" interval="10000" />
<service id="service2" interval="5000" />
<activity id="activity1" interval="50000" />
<root>
我將有一個類(Service
),通常處理服務標籤,並完成一些操作,然後「返回我」值,以便我可以重定向到另一個通道。
public class Service {
public int execute() {
// Execute the task and return the value to continue the "chain"
}
}
我知道有點難以解釋我必須做什麼......但是我已經用一個小例子更新了我的問題。現在我會看看你的鏈接 – Mistre83
我想到的是「拆分」標籤並提取間隔。此間隔將需要提交任務(由ScheduledExecutorService - scheduleAtFixedRate完成) – Mistre83
請參閱我對一個解決方案的編輯。 –