1
<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} 设置为“id”字段的示例代码,但由于它支持消息正文作为 SolrInputDocument 或等效的 XML,我想如何在上述 XML 路由中做到这一点?

4

1 回答 1

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

于 2012-10-31T17:29:59.360 回答