如何将solrInputDocument或XML作为值添加到camel-solr xml路由中?

时间:2012-10-30 23:53:23

标签: apache-camel

<route>
    <from uri="direct:insert"/>
    <setHeader headerName="SolrOperation">
        <constant>INSERT</constant>
    </setHeader>
    <setHeader headerName="SolrField.id">
        <simple>${body}</simple>
    </setHeader>
    <to uri="solr://localhost:8983/solr"/>
</route>

这是将$ {body}设置为&#39; id&#39;的示例代码。字段,但因为它支持消息体作为SolrInputDocument或等效的XML,我怎么想在上面的XML路由中做到这一点?

1 个答案:

答案 0 :(得分:0)

如果你有SolrInputDocument,那么只需将它作为消息正文传递给路由,并确保正确设置OPERATION标题......

//example producer code
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "MA147LL/A", 1.0f);
template.sendBodyAndHeader("direct:start", doc, SolrConstants.OPERATION, SolrConstants.OPERATION_INSERT);

//simplified route that just expects the message body and OPERATION header are setup appropriately
<from uri="direct:insert"/>
<to uri="solr://localhost:8983/solr"/>

请参阅单元测试以获取更多信息......

https://svn.apache.org/repos/asf/camel/trunk/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrUpdateTest.java