2013-01-18 40 views
2

我必須將我的對象(CcRequest)以Json格式存儲在DeadLetterQueue中。駱駝序列化JSON在死信隊列中

怎麼可能?

這裏我簡單的背景:

<camelContext id="el1DMRCamelContext" autoStartup="true" xmlns="http://camel.apache.org/schema/blueprint" > 

    <template id="producerTemplate" /> 

    <!-- Routes --> 
    <route id="createCcProcessorRoute" errorHandlerRef="createCcErrorHandler" > 
     <from uri="activemq:queue:createCc" /> 
     <process ref="createCcProcessor" /> 
    </route> 
</camelContext> 

<bean id="createCcErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder" > 
    <property name="deadLetterUri" value="activemq:queue:createCcDLQ" /> 
    <property name="redeliveryPolicy" ref="redeliveryPolicy" /> 
</bean> 

我想我在我的ActiveMQ對象(CcRequest在交換體放養):隊列:createCcDLQ採用JSON格式而不是二進制文件。

可能嗎?

回答

2

我不會將你想要做的事情分類爲死信處理程序。死信通常只是移動/重新傳送原始信息。

這很簡單,你使用excetion子句代替。

<dataFormats> 
    <json id="jsonFormat" library="Jackson"/> 
</dataFormats> 


<onException> 
    <exception>java.lang.RuntimeException</exception> 
    <marshal ref="jsonFormat"/> 
    <to uri="activemq:queue:createCcDLQ"/> 
</onException> 

Camel Exception Clause docs

Camel JSON docs

+0

真不錯,不知道onException的! – kinaesthesia