Вопрос

I have a storm Topology and one bolt inside it should interact with ElasticSearch.

public static Client client;
public static Settings settings;
public SomeBolt(){
    settings =
            ImmutableSettings.settingsBuilder().put("cluster.name", "elasticsearch").build();
    client = new TransportClient(settings)
            .addTransportAddress(new InetSocketTransportAddress("someip", 9300));

}

It works great when I run topology in local mode, but when I try to run this in cluster mode, that client gets null value and cannot execute next step.

I even tried to run it in supervisor machine in local mode, and it works. Only when in cluster mode it fails to get TransportClient.

Is there any possible reason?

Это было полезно?

Решение

You must keep in mind all spouts and bolts have to be serializable because they are (potentially) going to be moved around the net between their construction and their startup.

For that reason, in the constructor you can't (for example) open any network connection (like creating the ES client in your case). You must do it on the prepare method of the bolt.

In addition I'd recommend you to declare the Client as transient (and not static).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top