Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not connect to Zookeeper when create topic #33

Open
xmuyoo opened this issue Jul 13, 2016 · 2 comments
Open

Can not connect to Zookeeper when create topic #33

xmuyoo opened this issue Jul 13, 2016 · 2 comments

Comments

@xmuyoo
Copy link

xmuyoo commented Jul 13, 2016

Hi
I receive an exception when I create a topic:

org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server within timeout: 30000
at org.I0Itec.zkclient.ZkClient.connect(ZkClient.java:1232)
at org.I0Itec.zkclient.ZkClient.(ZkClient.java:156)
at org.I0Itec.zkclient.ZkClient.(ZkClient.java:130)
at kafka.utils.ZkUtils$.createZkClientAndConnection(ZkUtils.scala:75)
at kafka.utils.ZkUtils$.apply(ZkUtils.scala:57)
at kafka.utils.ZkUtils.apply(ZkUtils.scala)
at info.batey.kafka.unit.KafkaUnit.createTopic(KafkaUnit.java:170)
at info.batey.kafka.unit.KafkaUnit.createTopic(KafkaUnit.java:153)

and my code is like this:
`
import com.google.common.base.Throwables;
import info.batey.kafka.unit.KafkaUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class TestClass {

private static final int KAFKA_PORT = 2181;
private static final int ZK_PORT = 9092;

private static final String SOURCE_TOPIC = "source-topic";
private static final String ISSUE_TOPIC = "issue-topic";
private static final String CRASH_TOPIC = "crash-topic";

private KafkaUnit kafkaServer;

@Before
public void setup() {

    try {
        kafkaServer = new KafkaUnit(ZK_PORT, KAFKA_PORT);

        kafkaServer.createTopic(SOURCE_TOPIC);
        kafkaServer.createTopic(ISSUE_TOPIC);
        kafkaServer.createTopic(CRASH_TOPIC);
    } catch (Exception e) {
        Throwables.propagate(e);
    }
    kafkaServer.startup();
}

@Test
public void testConsumer() {
}

@After
public void tearDown() {
    if (null != kafkaServer)
        kafkaServer.shutdown();
}

}
`

I don't know how to fix this. Any suggestions are thankful!

@narendrasfo
Copy link

I am also getting same error , is there any way to resolve this

@1ambda
Copy link

1ambda commented Aug 26, 2016

@Muyoo @narendrasfo you should call startup before createTopic

IMO, README should include whole code example including preparing for a kafka server instead of providing partial one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants