Hello,

I am currently working on a project in which I need to keep ZooKeeper
object members in the bolts of my topology. Am I allowed to do that? For
instance, can I have something like the following:

public class MyBolt extends BaseRichBolt {

    private ZooKeeper zk;

    public void prepare(Map conf, TopologyContext context, OutputCollector
collector) {
        zk = new ZooKeeper"127.0.0.1", 2181);
    }

    public void execute(Tuple tuple) {
        //Do something...
        zk.exists("/", false);
    }
    .....
}

The reason I am asking is because I know that a Bolt needs to be
Serializable and I have a feeling that a ZooKeeper object is not (I am
pretty confident about that, since it keeps a socket connection with the
zookeeper server). Can somebody give me more information on the topic?
Also, If I go ahead and use something like what I described earlier, what
might be the possible problems that I might run into? Apparently, in local
mode the above works.

Thank you,
Nick

Reply via email to