Obtaining an TransportClient via Spring Inject?


(Franz Allan Valencia See) #1

Good day,

I am currently instantiating a Client similar to
http://www.elasticsearch.com/docs/elasticsearch/java_api/client/#TransportClientusing
spring, which implies that I only instantiate this once and use it
everywhere. Is that the proper way to use it?

I am not sure when the 'sniffing' occurs. Does it occur during client
creation or for every client#get(..) invocation?

Thanks,

Franz Allan Valencia See | Java Software Engineer
franz.see@gmail.com
LinkedIn: http://www.linkedin.com/in/franzsee
Twitter: http://www.twitter.com/franz_see


(Shay Banon) #2

Yes, you should shard the client as a "singleton". The sniffing happens in
the background, based on the list of addresses provided.

-shay.banon

On Wed, Jul 28, 2010 at 3:18 AM, Franz Allan Valencia See <
franz.see@gmail.com> wrote:

Good day,

I am currently instantiating a Client similar to
http://www.elasticsearch.com/docs/elasticsearch/java_api/client/#TransportClientusing spring, which implies that I only instantiate this once and use it
everywhere. Is that the proper way to use it?

I am not sure when the 'sniffing' occurs. Does it occur during client
creation or for every client#get(..) invocation?

Thanks,

Franz Allan Valencia See | Java Software Engineer
franz.see@gmail.com
LinkedIn: http://www.linkedin.com/in/franzsee
Twitter: http://www.twitter.com/franz_see


(erez) #3

Take a look at this post:

http://techo-ecco.com/blog/elasticsearch-with-spring/

I have a TransportClientFactoryBean example here:


(Karussell) #4

I'm using guice and essentially this 4 lines in Module.configure:

Settings s = ImmutableSettings.settingsBuilder().put("cluster.name",
cluster).build();
TransportClient tmp = new TransportClient(s);
tmp.addTransportAddress(new InetSocketTransportAddress(url, port));
bind(MyCustomWrapper.class).toInstance(new MyCustomWrapper(tmp));

Then all I need is:

@Inject private Provider myIndexProvider;

to access ElasticSearch in my UI or elsewhere via:
myIndexProvider.get().doSomething();

On 10 Jul., 12:57, erez erezma...@gmail.com wrote:

Take a look at this post:

http://techo-ecco.com/blog/elasticsearch-with-spring/

I have a TransportClientFactoryBean example here:

https://github.com/erezmazor/projectx/blob/master/org.projectx.elasti...

--
View this message in context:http://elasticsearch-users.115913.n3.nabble.com/Obtaining-an-Transpor...
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(system) #5