313.5. Example
以下是简单的 INSERT、DELETE 和 COMMIT 示例
from("direct:insert") .setHeader(SolrConstants.OPERATION, constant(SolrConstants.OPERATION_INSERT)) .setHeader(SolrConstants.FIELD + "id", body()) .to("solr://localhost:8983/solr"); from("direct:delete") .setHeader(SolrConstants.OPERATION, constant(SolrConstants.OPERATION_DELETE_BY_ID)) .to("solr://localhost:8983/solr"); from("direct:commit") .setHeader(SolrConstants.OPERATION, constant(SolrConstants.OPERATION_COMMIT)) .to("solr://localhost:8983/solr");
<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> <route> <from uri="direct:delete"/> <setHeader headerName="SolrOperation"> <constant>DELETE_BY_ID</constant> </setHeader> <to uri="solr://localhost:8983/solr"/> </route> <route> <from uri="direct:commit"/> <setHeader headerName="SolrOperation"> <constant>COMMIT</constant> </setHeader> <to uri="solr://localhost:8983/solr"/> </route>
客户端只需将正文消息传递给插入或删除路由,然后调用提交路由。
template.sendBody("direct:insert", "1234"); template.sendBody("direct:commit", null); template.sendBody("direct:delete", "1234"); template.sendBody("direct:commit", null);