You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by "Stig Rohde Døssing (JIRA)" <ji...@apache.org> on 2016/09/23 13:11:20 UTC

[jira] [Commented] (KAFKA-2392) Kafka Server does not accept 0 as a port

    [ https://issues.apache.org/jira/browse/KAFKA-2392?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15516397#comment-15516397 ] 

Stig Rohde Døssing commented on KAFKA-2392:
-------------------------------------------

I don't know if this helps you, but this can already be done if you're willing to run Kafka in-memory. We're using Curator's TestingServer to run an in-memory Zookeeper, which allows you to get the assigned port https://curator.apache.org/apidocs/org/apache/curator/test/TestingServer.html#getConnectString--. You can then use that string to start an in-memory Kafka broker. 

{code}
TestingServer testingServer = new TestingServer()
Properties properties = new Properties();
properties.setProperty("zookeeper.connect", testingServer.getConnectString());
properties.setProperty("advertised.host.name", "localhost");
properties.setProperty("host.name", "localhost");
properties.setProperty("port", "0");

KafkaServer server = new KafkaServer(new KafkaConfig(properties), new SystemTime(), scala.Option$.MODULE$.apply(null));
server.startup();
{code}
Where SystemTime is this
{code}

public class SystemTime implements Time {
    public long milliseconds() {
        return System.currentTimeMillis();
    }

    public long nanoseconds() {
        return System.nanoTime();
    }

    public void sleep(long ms) {
        try {
            Thread.sleep(ms);
        } catch (InterruptedException e) {
            // Ignore
        }
    }
}
{code}
We're on Kafka 0.9.0.1, the parameters may be slightly different on 0.8.

> Kafka Server does not accept 0 as a port
> ----------------------------------------
>
>                 Key: KAFKA-2392
>                 URL: https://issues.apache.org/jira/browse/KAFKA-2392
>             Project: Kafka
>          Issue Type: Bug
>          Components: config
>    Affects Versions: 0.8.2.1
>            Reporter: Buğra Gedik
>            Priority: Minor
>
> I want to specify 0 as a port number for Zookeeper as well as Kafka Server. For instance server.properties configuration file has a 'port' property, but does not accept 0 as a value. Similarly, zookeeper.properties has a 'clientPort' property, but does not accept 0 as a value.
> I want 0 to specify that the port will be selected automatically (OS assigned). In my use case, I want to run Zookeeper with an automatically picked port, and use that port to create a Kafka Server configuration file, that specifies the Kafka Server port as 0 as well. I parse the output from the servers to figure out the actual ports used. All this is needed for a testing environment.
> Not supporting automatically selected ports makes it difficult to run Kafka server as part of our tests.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)