Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: CAMEL-6827

...

Maven users will need to add the following dependency to their pom.xml for this component:

Code Block
xml
xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-solr</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

NOTE: solrs and solrCloud are new added since Camel 2.14.

Code Block
solr://host[:port]/solr?[options]

solrs://host[:port]/solr?[options]
solrCloud://host[:port]/solr?[options]

Endpoint Options

The following SolrServer options may be configured on the Solr endpoint.

name

default value

description

maxRetries

0

maximum number of retries to attempt in the event of transient errors

soTimeout

1000

read timeout on the underlying HttpConnectionManager. This is desirable for queries, but probably not for indexing

connectionTimeout

100

connectionTimeout on the underlying HttpConnectionManager

defaultMaxConnectionsPerHost

2

maxConnectionsPerHost on the underlying HttpConnectionManager

maxTotalConnections

20

maxTotalConnection on the underlying HttpConnectionManager

followRedirects

false

indicates whether redirects are used to get to the Solr server

allowCompression

false

server side must support gzip or deflate for this to have any effect

requestHandler

/update (xml)

set the request handler to be used

streamingThreadCount

2

Camel 2.9.2 set the number of threads for the StreamingUpdateSolrServer

streamingQueueSize

10

Camel 2.9.2 set the queue size for the StreamingUpdateSolrServer

zkhostnullCamel 2.14.0 set the zoo keeper host information which the solrCloud could use, such as "zkhost=localhost:8123".
collectionnullCamel 2.14.0 set the collection name which the solrCloud server could use

Message Operations

The following Solr operations are currently supported. Simply set an exchange header with a key of "SolrOperation" and a value set to one of the following. Some operations also require the message body to be set.

...

Below is a simple INSERT, DELETE and COMMIT example

Code Block
java
java

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");
Code Block
xml
xml

<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>

A client would simply need to pass a body message to the insert or delete routes and then call the commit route.

Code Block
java
java

    template.sendBody("direct:insert", "1234");
    template.sendBody("direct:commit", null);
    template.sendBody("direct:delete", "1234");
    template.sendBody("direct:commit", null);

...

Currently, this component doesn't support querying data natively (may be added later). For now, you can query Solr using HTTP as follows:

Code Block
java
java

//define the route to perform a basic query
from("direct:query")
    .recipientList(simple("http://localhost:8983/solr/select/?q=${body}"))
    .convertBodyTo(String.class);
...
//query for an id of '1234' (url encoded)
String responseXml = (String) template.requestBody("direct:query", "id%3A1234");

...

Solr Query Tutorial

Solr Query Syntax

Include Page
Endpoint See Also
Endpoint See Also