2017-07-26 130 views
13

我很新WSO2 ESB我有一個實現具有此特定行爲的自定義消息處理器:執行操作後,從消息存儲中檢索元素,並在執行與此消息處理器相關的序列之前如何爲自定義消息處理器實現自定義SamplingService?在此之後檢索元素並在執行序列之前

我試着詳細解釋它。

這是我的ESB消息處理器定義:

<?xml version="1.0" encoding="UTF-8"?> 
<!---<messageProcessor class="org.apache.synapse.message.processor.impl.sampler.SamplingProcessor" messageStore="transferFromMessageStore" name="transferFromMessageProcessor" xmlns="http://ws.apache.org/ns/synapse">--> 
<messageProcessor class="com.mycompany.toolkit.messageprocessor.SamplingProcessorHeaderRateLimitation" messageStore="transferFromMessageStore" name="transferFromMessageProcessor" xmlns="http://ws.apache.org/ns/synapse"> 
    <parameter name="sequence">transferProcessorSequence</parameter> 
    <parameter name="interval">1000</parameter> 
    <parameter name="is.active">true</parameter> 
    <parameter name="concurrency">1</parameter> 
</messageProcessor> 

它檢索某些元素(XML文檔)形成transferFromMessageStore(隊列),並且該對象傳遞到使用transferProcessorSequence.xml序列它。正如您在此時看到的,我已經實現了一個自定義消息處理器SamplingProcessorHeaderRateLimit,它簡單地擴展了WSO2類的org.apache.synapse.message.processor.impl.sampler.SamplingProcessor。此時它僅在執行init()方法時顯示日誌。我將它部署在我的Carbon服務器上,並且工作正常。

Here你可以找到整個項目代碼。

好,但是從我所瞭解,以獲得所需的行爲我沒有簡單地延長SamplingProcessor類,因爲爲了做到每封郵件的消費和調度的序列之間的自定義實現,需要擴展類SamplingService類,這個one

我認爲我需要重寫的execute()取(的MessageConsumer msgConsumer)

此時應該還可以插入日誌,每次從消息存儲中檢索元素並在此之前執行與消息處理器相關的序列時,都會寫入日誌文件。

可能嗎?

所以我的主要主杜省是:

1)有我創建擴展SamplingService類在同一個項目中,我實現我的自定義消息處理器(此行爲的類必須使用僅用於我的WSO2 ESB項目中的特定消息處理器,此項目中使用的所有其他消息處理器必須使用標準SamplingService實現)。

2)另一個疑問是關於如何將此自定義SamplingService實現傳遞給我的自定義消息處理器。進入SamplingProcessor WSO2類(如何將特定的自定義消息處理器實現與處理其生命週期的自定義SamplingService實現關聯)。

+0

2問題爲什麼不重寫com.mycompany.toolkit.messageprocessor.SamplingProcessorHeaderRateLimitation中的getTask方法(它保護了modifer),並返回自己的類來擴展SamplingService? – simar

+0

@simar你什麼意思?在這個時候,我已經覆蓋了getTask()方法,只是簡單地把它放在log \ println消息中(僅用於測試puropose)。問題是我從來沒有獲得這個輸出到我的日誌文件(相反,我獲得init()方法日誌)。所以在我看來,這個getTask()方法從來沒有執行的原因。你有一些關於它的想法嗎?也許是受保護的修飾符? – AndreaNobili

+0

調用log.info()僅在您正確配置爲在文件中可見的日誌中可見。調用System.out.println只在控制檯中可見。你是否嘗試在控制檯模式下運行並在getTask方法中查找println消息?您是否嘗試在調試模式下運行wsoesb並嘗試調試以查看發生了什麼問題 – simar

回答

1
1) Have I to create a class extending the SamplingService class into the same project in which I am implementing my custom message processor (this behavior have to be used only for this specific message processor in my WSO2 ESB project, all the other message processor used in this project have to use the standard SamplingService implementation). 

您的自定義SamplingProcessorHeaderRateLimitation只會消耗進去,到transferFromMessageStore消息,並會注入其消耗和處理才序列transferProcessorSequence消息。此消息處理器不會處理所有其他路徑。

2) Another doubt is related about how this custom SamplingService implementation is passed to my custom message processor. Into the the SamplingProcessor WSO2 class (how to associate a specific custom message processor implementation with a custom SamplingService implementation handling its lifecycle). 

如果你看看你的源代碼來實現SamplingProcessorHeaderRateLimitation.getTask()你有你的自定義SamplingProcessorHeaderRateLimitation

@Override 
protected Task getTask() { 
    logger.info("getTask() START"); 
    System.out.println("getTask() START"); 
    logger.info("getTask() END"); 
    System.out.println("getTask() END"); 
    return (Task) new SamplingService2(this, synapseEnvironment, CONCURRENCY, SEQUENCE, isProcessorStartAsDeactivated()); 
} 
+0

我的疑問是:正如你所看到的,當getTask()方法啓動並且返回時,我會放入一些logger \ println,但它會返回,但這些日誌不會出現在日誌文件中將日誌放入存在於我的日誌文件中的init()方法中)。所以在我看來,由於某種原因,getTask()方法從不執行(它只是一個假設),它仍然使用標準的SamplingService實現。你對此有進一步的想法嗎?謝謝 – AndreaNobili

+0

在這裏有什麼問題(從github上次檢查源)。 SamplingService2不推動任務接口,因此它不能轉換爲任務。它假設拋出ClassCastException – simar

0

你在XML配置任務捆綁您的自定義SamplingService2

<task name="CheckPrice" class="org.wso2.esb.tutorial.tasks.PlaceStockOrderTask"> 
    <trigger interval="5000"/> 
</task> 

<task name="CheckPrice" class="org.wso2.esb.tutorial.tasks.PlaceStockOrderTask"> 
    <trigger interval="5000" count="10"/> 
</task> 
0

Q1:

有我創建一個類擴展SamplingService類到 同一個項目中,我實現我的自定義消息處理器 (這種行爲只能用於我的WSO2 ESB項目中的這個特定消息 處理器,al l在本項目中使用的其他消息處理器 必須使用標準SamplingService 實現)。

<messageProcessor class="com.mycompany.toolkit.messageprocessor.SamplingProcessorHeaderRateLimitation" messageStore="transferFromMessageStore" name="transferFromMessageProcessor" xmlns="http://ws.apache.org/ns/synapse"> 
<parameter name="sequence">transferProcessorSequence</parameter> 

定製處理器和服務將當它被指定爲在處理器類,如上面在實施例僅使用。

Q2:

另一個疑問是這個自訂SamplingService 實現是如何傳遞給我的自定義消息處理器相關。進入 SamplingProcessor WSO2類(如何將特定定製 消息處理器實現與處理其生命週期的自定義SamplingService 實現相關聯)。

可以直接擴展/實施ScheduledMessageProcessor而非SamplingProcessor,因爲它僅實現getTask()和初始化在init()方法視圖對象。 另外您的SamplingService2類應擴展Task ManagedLifecycle接口。

相關問題