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

Not able to connect Kafka broker outside of docker-compose #456

Closed
Zizou84 opened this issue Feb 5, 2019 · 4 comments
Closed

Not able to connect Kafka broker outside of docker-compose #456

Zizou84 opened this issue Feb 5, 2019 · 4 comments

Comments

@Zizou84
Copy link

Zizou84 commented Feb 5, 2019

Hello,
I am running kafka from docker-compose.yml

kafka:
      depends_on:
        kafka-broker-config:
          condition: service_started
        zookeeper:
          condition: service_healthy
      environment:
        KAFKA_ADVERTISED_LISTENERS: SASL_PLAINTEXT://MY_EXTERNAL_IP:9092
        KAFKA_LISTENERS: SASL_PLAINTEXT://:9092
        KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
        KAFKA_LOG_DIRS: /kafka/kafka-logs
        KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
        KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
        KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      image: wurstmeister/zookeeper
      ports:
      - 9092:9092
      - 9016:9016
      stdin_open: true
      tty: true

I have some services within this docker-compose file, they are able to connect to kafka only if i replace MY_EXTERNAL_IP:9092 by kafka:9092
For external applications outside my docker-compose file, Im' not able to connect my broker

Here is the error I'm getting when connection from external application:

2019-02-05 19:08:30,601 [main] TRACE org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Found least loaded node MY_EXTERNAL_IP:9092 (id: -1 rack: null)
2019-02-05 19:08:30,602 [main] DEBUG org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Initialize connection to node MY_EXTERNAL_IP:9092 (id: -1 rack: null) for sending metadata request
2019-02-05 19:08:30,602 [main] DEBUG org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Initiating connection to node MY_EXTERNAL_IP:9092 (id: -1 rack: null)
2019-02-05 19:08:35,323 [main] DEBUG org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Completed connection to node -1. Fetching API versions.
2019-02-05 19:08:35,325 [main] TRACE org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Found least loaded node MY_EXTERNAL_IP:9092 (id: -1 rack: null)
2019-02-05 19:08:35,329 [main] TRACE org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Found least loaded node MY_EXTERNAL_IP:9092 (id: -1 rack: null)
2019-02-05 19:08:35,364 [main] TRACE org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Found least loaded node MY_EXTERNAL_IP:9092 (id: -1 rack: null)
2019-02-05 19:08:35,407 [main] TRACE org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Found least loaded node MY_EXTERNAL_IP:9092 (id: -1 rack: null)
2019-02-05 19:08:35,443 [main] DEBUG org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Initiating API versions fetch from node -1.
2019-02-05 19:08:35,446 [main] TRACE org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] No version information found when sending API_VERSIONS with correlation id 0 to node -1. Assuming version 1.
2019-02-05 19:08:35,447 [main] TRACE org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Sending API_VERSIONS {} with correlation id 0 to node -1
2019-02-05 19:08:35,450 [main] TRACE org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Found least loaded node MY_EXTERNAL_IP:9092 (id: -1 rack: null)
2019-02-05 19:08:35,451 [main] TRACE org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Found least loaded node MY_EXTERNAL_IP:9092 (id: -1 rack: null)
2019-02-05 19:08:35,490 [main] TRACE org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Completed receive from node -1 for API_VERSIONS with correlation id 0, received {error_code=0,api_versions=[{api_key=0,min_version=0,max_version=5},{api_key=1,min_version=0,max_version=7},{api_key=2,min_version=0,max_version=2},{api_key=3,min_version=0,max_version=5},{api_key=4,min_version=0,max_version=1},{api_key=5,min_version=0,max_version=0},{api_key=6,min_version=0,max_version=4},{api_key=7,min_version=0,max_version=1},{api_key=8,min_version=0,max_version=3},{api_key=9,min_version=0,max_version=3},{api_key=10,min_version=0,max_version=1},{api_key=11,min_version=0,max_version=2},{api_key=12,min_version=0,max_version=1},{api_key=13,min_version=0,max_version=1},{api_key=14,min_version=0,max_version=1},{api_key=15,min_version=0,max_version=1},{api_key=16,min_version=0,max_version=1},{api_key=17,min_version=0,max_version=1},{api_key=18,min_version=0,max_version=1},{api_key=19,min_version=0,max_version=2},{api_key=20,min_version=0,max_version=1},{api_key=21,min_version=0,max_version=0},{api_key=22,min_version=0,max_version=0},{api_key=23,min_version=0,max_version=0},{api_key=24,min_version=0,max_version=0},{api_key=25,min_version=0,max_version=0},{api_key=26,min_version=0,max_version=0},{api_key=27,min_version=0,max_version=0},{api_key=28,min_version=0,max_version=0},{api_key=29,min_version=0,max_version=0},{api_key=30,min_version=0,max_version=0},{api_key=31,min_version=0,max_version=0},{api_key=32,min_version=0,max_version=1},{api_key=33,min_version=0,max_version=0},{api_key=34,min_version=0,max_version=0},{api_key=35,min_version=0,max_version=0},{api_key=36,min_version=0,max_version=0},{api_key=37,min_version=0,max_version=0},{api_key=38,min_version=0,max_version=0},{api_key=39,min_version=0,max_version=0},{api_key=40,min_version=0,max_version=0},{api_key=41,min_version=0,max_version=0},{api_key=42,min_version=0,max_version=0}],throttle_time_ms=0}
2019-02-05 19:08:35,496 [main] DEBUG org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Recorded API versions for node -1: (Produce(0): 0 to 5 [usable: 5], Fetch(1): 0 to 7 [usable: 7], ListOffsets(2): 0 to 2 [usable: 2], Metadata(3): 0 to 5 [usable: 5], LeaderAndIsr(4): 0 to 1 [usable: 1], StopReplica(5): 0 [usable: 0], UpdateMetadata(6): 0 to 4 [usable: 4], ControlledShutdown(7): 0 to 1 [usable: 1], OffsetCommit(8): 0 to 3 [usable: 3], OffsetFetch(9): 0 to 3 [usable: 3], FindCoordinator(10): 0 to 1 [usable: 1], JoinGroup(11): 0 to 2 [usable: 2], Heartbeat(12): 0 to 1 [usable: 1], LeaveGroup(13): 0 to 1 [usable: 1], SyncGroup(14): 0 to 1 [usable: 1], DescribeGroups(15): 0 to 1 [usable: 1], ListGroups(16): 0 to 1 [usable: 1], SaslHandshake(17): 0 to 1 [usable: 1], ApiVersions(18): 0 to 1 [usable: 1], CreateTopics(19): 0 to 2 [usable: 2], DeleteTopics(20): 0 to 1 [usable: 1], DeleteRecords(21): 0 [usable: 0], InitProducerId(22): 0 [usable: 0], OffsetForLeaderEpoch(23): 0 [usable: 0], AddPartitionsToTxn(24): 0 [usable: 0], AddOffsetsToTxn(25): 0 [usable: 0], EndTxn(26): 0 [usable: 0], WriteTxnMarkers(27): 0 [usable: 0], TxnOffsetCommit(28): 0 [usable: 0], DescribeAcls(29): 0 [usable: 0], CreateAcls(30): 0 [usable: 0], DeleteAcls(31): 0 [usable: 0], DescribeConfigs(32): 0 to 1 [usable: 1], AlterConfigs(33): 0 [usable: 0], AlterReplicaLogDirs(34): 0 [usable: 0], DescribeLogDirs(35): 0 [usable: 0], SaslAuthenticate(36): 0 [usable: 0], CreatePartitions(37): 0 [usable: 0], CreateDelegationToken(38): 0 [usable: 0], RenewDelegationToken(39): 0 [usable: 0], ExpireDelegationToken(40): 0 [usable: 0], DescribeDelegationToken(41): 0 [usable: 0], DeleteGroups(42): 0 [usable: 0])
2019-02-05 19:08:35,496 [main] TRACE org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Found least loaded node MY_EXTERNAL_IP:9092 (id: -1 rack: null)
2019-02-05 19:08:35,497 [main] DEBUG org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Sending metadata request (type=MetadataRequest, topics=myTopic) to node MY_EXTERNAL_IP:9092 (id: -1 rack: null)
2019-02-05 19:08:35,498 [main] TRACE org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Sending METADATA {topics=[myTopic],allow_auto_topic_creation=true} with correlation id 1 to node -1
2019-02-05 19:08:35,544 [main] TRACE org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Completed receive from node -1 for METADATA with correlation id 1, received {throttle_time_ms=0,brokers=[],cluster_id=_IMuGaXqQDq3ZONuBy7Khw,controller_id=-1,topic_metadata=[{error_code=29,topic=myTopic,is_internal=false,partition_metadata=[]}]}
2019-02-05 19:08:35,546 [main] WARN  org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-1, groupId=integration_AAAA] Error while fetching metadata with correlation id 1 : {myTopic=TOPIC_AUTHORIZATION_FAILED}

Any help or explanation please?

@sscaling
Copy link
Collaborator

sscaling commented Feb 5, 2019

image: wurstmeister/zookeeper is incorrect

I'd recommend using PLAINTEXT as the security protocol, and once that is working you can concentrate on getting SASL_PLAINTEXT working.

If you can provide a minimal docker-compose example along with the commands used to connect to the service we can try and reproduce and provide feedback. I would recommend including kafkacat command used to connect to the broker to remove your application from the equation.

As an aside, depends_on has deprecated the condition behaviour (https://docs.docker.com/compose/compose-file/#depends_on)

@sscaling
Copy link
Collaborator

sscaling commented Feb 8, 2019

No response from OP, so closing issue. Please re-open if you can reproduce issue with minimal configuration and provide requested information (config, logs, commands used etc)

Thanks.

@sscaling sscaling closed this as completed Feb 8, 2019
@effinger-rh
Copy link

same problem here, I'll admit I'm new to docker-compose networking. When I run kafkacat -b localhost -t topicname... it reports networking error:
% ERROR: Local: Host resolution failure: broker:9092/1: Failed to resolve 'broker:9092': nodename nor servname provided, or not known (after 1ms in state CONNECT)

@ojitha
Copy link

ojitha commented Mar 20, 2022

same problem

Error connecting to node broker:29092 (id: 1 rack: null)

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

No branches or pull requests

4 participants