ef-labs / vertx-elasticsearch-service

Vert.x elasticsearch service with event bus proxying
57 stars 18 forks source link

Unable (or unsure) how to use the module #7

Closed AlexThurston closed 9 years ago

AlexThurston commented 9 years ago

Hey, If this happens to be user error, then I apologize in advance for wasting your time. I'm very interested in using this module but can't seem to get it to work and have tried several different ways.

The first was just running the module explicitly: vertx runmod com.englishtown~vertx-mod-elasticsearch~1.3.0 -conf my.conf

my.conf contains:

{
  "address": "eb.elasticsearch",
  "transportAddresses": [{ "hostname": "10.0.42.1", "port": 9200 }]
}

This fails in the following manner:

Failed in deploying module
java.lang.InstantiationException: com.englishtown.vertx.elasticsearch.ElasticSearch
    at java.lang.Class.newInstance(Class.java:364)
    at org.vertx.java.platform.impl.java.JavaVerticleFactory.createVerticle(JavaVerticleFactory.java:57)
    at org.vertx.java.platform.impl.DefaultPlatformManager$21.run(DefaultPlatformManager.java:1740)
    at org.vertx.java.core.impl.DefaultContext$3.run(DefaultContext.java:175)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:370)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    at java.lang.Thread.run(Thread.java:745)

No matter how I try to use the module, I continue to get that very same error. Any thoughts or insight on what I'm doing wrong. The exception doesn't really tell me where/what is the problem.

Again, sorry if this is something boneheaded.

adrianluisgonzalez commented 9 years ago

The problem is the ElasticSearch verticle uses DI which won't work with the default vert.x JavaVerticleFactory.

Take a look at this section: https://github.com/englishtown/vertx-elasticsearch-service/tree/1.3.0#dependency-injection-and-the-hk2verticlefactory

If you don't want to use HK2 or Guice (or any DI framework), you could wrap the com.englishtown.vertx.elasticsearch.ElasticSearch verticle and provide instances of TransportClientFactory and ElasticSearchConfigurator yourself.

Hope this helps.

AlexThurston commented 9 years ago

I've made some progress and now appear to be using the module successfully. However, I've got some other questions. There are perhaps not directly related to this module perse, but you've made the mistake of being helpful :)

I currently have a main "run" ruby file that deploys the various verticles. Some of these verticles are written in ruby and others are written in Java. If I change the langs.properties as suggested, things work but does that not mean that ALL my other java verticles will be using the HK2 DI framework? Is that bad?

I guess the crux of my issue is that I'd like to be able to deploy a module specifying the prefix. According to the Vert.x docs, I can do that with a verticle but it doesn't seem to work with a module. Basically I wanted to deploy your module with HK2 but continue to deploy the other java verticles using the stock Java instantiater.

I see this when I set java to the HK2 Factory in the langs.properties file: HK2 bootstrap binder class com.englishtown.vertx.hk2.BootstrapBinder was not found. Are you missing injection bindings?

But the system still appears to be working just fine.

adrianluisgonzalez commented 9 years ago

Unfortunately you can only choose one verticle factory per language with vert.x 2.x (as far as I know). This all changes with vert.x 3 (using prefixes as you mention), but that doesn't help you for the time being.

We run all our vert.x apps using the HK2VerticleFactory. You can see the source code https://github.com/englishtown/vertx-hk2. All it does is create an HK2 ServiceLocator, read any DI bindings that have been configured, and use that to instantiation the verticle. The same is true for the GuiceVerticleFactory with a Guice Injector.

We do everything in Java using DI, but I understand that is not everyone's architectural choice. If you don't want to use DI, you can get around it by creating your own module that wraps the ElasticSearch verticle and you can instantiate the dependencies in your wrapper.

adrianluisgonzalez commented 9 years ago

Feel free to re-open if you're still having issues.