# Golang Code not connecting to topic when containerised

**URL:** <https://forum.confluent.io/t/golang-code-not-connecting-to-topic-when-containerised/1548>\
**Category:** Non-Java Clients\
**Created:** [21 April 2021 09:16 UTC](https://forum.confluent.io/t/golang-code-not-connecting-to-topic-when-containerised/1548 "2021-04-21T09:16:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![georgelza](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/georgelza/32/3026_2.png) [@georgelza](https://forum.confluent.io/u/georgelza)\
**Post date:** [21 April 2021 09:16 UTC](https://forum.confluent.io/t/golang-code-not-connecting-to-topic-when-containerised/1548/1 "2021-04-21T09:16:33Z")

</div>

… so having been able to compile 1/2 problem…

Please see below:

FYI: little lab app…  
Part A reads text file and publishes messages onto a topic.  
Part B (the below) consumers from topic and push via gRPC/Protobuf to a “poster”  
Part C “Poster” receives messages and does some more work, and eventually sinks messages into a Cassandra or PostgreSQL DB.

… so my code works fine if executed from a go file that I simply execute as go run consumer.go  
problem, when i package it via a dockerfile and push into a minikube environment it gives the below errors. I get these, trying to connect to a CP stack deployed using the cp\_all\_in\_one deployment using docker-compose and similarly get it if I do the local zip file with s"confluent local services start"

I’ve tried to point my client/consumer to the localhost from inside the pod/container and also to a physical ip.

```auto
INFO: 2021/04/21 09:06:22 Retrieving variables ..
INFO: 2021/04/21 09:06:22 Hostname is scrubber-55fdcfcc8-xmbsc
INFO: 2021/04/21 09:06:22 gRPC Server is localhost
INFO: 2021/04/21 09:06:22 gRPC Port is 9010
INFO: 2021/04/21 09:06:22 Kafka Broker is 192.168.49.2
INFO: 2021/04/21 09:06:22 Kafka Port is 9092
INFO: 2021/04/21 09:06:22 Kafka Topic is people_pb
INFO: 2021/04/21 09:06:22 Kafka # Parts is 3
INFO: 2021/04/21 09:06:22 Kafka Rep Factor is 1
INFO: 2021/04/21 09:06:22 Kafka Retension is 3600000
INFO: 2021/04/21 09:06:22 Kafka Group is tmg1
INFO: 2021/04/21 09:06:22 Debug Level is 2
INFO: 2021/04/21 09:06:22
INFO: 2021/04/21 09:06:22 ****Configure Admin Kafka Connection****
INFO: 2021/04/21 09:06:22 acm_str is 192.168.49.2:9092
%3|1618995982.047|FAIL|rdkafka#producer-1| [thrd:192.168.49.2:9092/bootstrap]: 192.168.49.2:9092/bootstrap: Connect to ipv4#192.168.49.2:9092 failed: Connection refused (after 0ms in state CONNECT)
INFO: 2021/04/21 09:06:22 Admin client created
INFO: 2021/04/21 09:06:22 Context object created
INFO: 2021/04/21 09:06:22 ParseDuration Configured
INFO: 2021/04/21 09:06:22 [retention.ms](http://retention.ms/) Configured
%3|1618995983.049|FAIL|rdkafka#producer-1| [thrd:192.168.49.2:9092/bootstrap]: 192.168.49.2:9092/bootstrap: Connect to ipv4#192.168.49.2:9092 failed: Connection refused (after 0ms in state CONNECT, 1 identical error(s) suppressed)
%6|1618996011.041|FAIL|rdkafka#producer-1| [thrd:192.168.49.2:9092/bootstrap]: 192.168.49.2:9092/bootstrap: Disconnected while requesting ApiVersion: might be caused by incorrect security.protocol configuration (connecting to a SSL listener?) or broker version is < 0.10 (see api.version.request) (after 3ms in state APIVERSION_QUERY)

```

anyone with ideas ?

if anyone have a go file + accompanying dockerfile that they know works, would love it, then I can confirm it’s not code but a setting, which I’m sure it is.

---

<div class="post-metadata">

**Author:** ![georgelza](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/georgelza/32/3026_2.png) [@georgelza](https://forum.confluent.io/u/georgelza)\
**Post date:** [21 April 2021 09:47 UTC](https://forum.confluent.io/t/golang-code-not-connecting-to-topic-when-containerised/1548/2 "2021-04-21T09:47:28Z")

</div>

… can add having the same errors when I simply do a docker build and a docker run (other words not using minikube)

```auto
INFO: 2021/04/21 09:47:46
INFO: 2021/04/21 09:47:46 ****Configure Admin Kafka Connection****
INFO: 2021/04/21 09:47:46 acm_str is localhost:9092
%3|1618998466.037|FAIL|rdkafka#producer-1| [thrd:localhost:9092/bootstrap]: localhost:9092/bootstrap: Connect to ipv4#127.0.0.1:9092 failed: Connection refused (after 0ms in state CONNECT)
INFO: 2021/04/21 09:47:46 Admin client created
INFO: 2021/04/21 09:47:46 Context object created
INFO: 2021/04/21 09:47:46 ParseDuration Configured
INFO: 2021/04/21 09:47:46 retention.ms Configured
%3|1618998467.037|FAIL|rdkafka#producer-1| [thrd:localhost:9092/bootstrap]: localhost:9092/bootstrap: Connect to ipv4#127.0.0.1:9092 failed: Connection refused (after 0ms in state CONNECT, 1 identical error(s) suppressed)

```

G

---

<div class="post-metadata">

**Author:** ![rmoff](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/rmoff/32/3_2.png) [@rmoff](https://forum.confluent.io/u/rmoff)\
**Post date:** [21 April 2021 10:06 UTC](https://forum.confluent.io/t/golang-code-not-connecting-to-topic-when-containerised/1548/3 "2021-04-21T10:06:32Z")

</div>

Hey George,

Have a look at this: [Why Can’t I Connect to Kafka? | Troubleshoot Connectivity](https://www.confluent.io/blog/kafka-client-cannot-connect-to-broker-on-aws-on-docker-etc/) and also [Learning Golang (some rough notes) - S02E08 - Checking Kafka advertised.listeners with Go](https://rmoff.net/2020/07/17/learning-golang-some-rough-notes-s02e08-checking-kafka-advertised.listeners-with-go/)

---

<div class="post-metadata">

**Author:** ![georgelza](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/georgelza/32/3026_2.png) [@georgelza](https://forum.confluent.io/u/georgelza)\
**Post date:** [21 April 2021 11:17 UTC](https://forum.confluent.io/t/golang-code-not-connecting-to-topic-when-containerised/1548/4 "2021-04-21T11:17:10Z")

</div>

thanks, will do, hopefully I’m just being dumb, not uncommon 😉

will report back.

G

---

<div class="post-metadata">

**Author:** ![georgelza](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/georgelza/32/3026_2.png) [@georgelza](https://forum.confluent.io/u/georgelza)\
**Post date:** [21 April 2021 12:55 UTC](https://forum.confluent.io/t/golang-code-not-connecting-to-topic-when-containerised/1548/5 "2021-04-21T12:55:44Z")

</div>

dumb question, but where is server.properties so that I can change the advertised.listener setting.

G

---

<div class="post-metadata">

**Author:** ![georgelza](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/georgelza/32/3026_2.png) [@georgelza](https://forum.confluent.io/u/georgelza)\
**Post date:** [21 April 2021 13:01 UTC](https://forum.confluent.io/t/golang-code-not-connecting-to-topic-when-containerised/1548/6 "2021-04-21T13:01:52Z")

</div>

found it…

/etc/kafka/

G

---

<div class="post-metadata">

**Author:** ![georgelza](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/georgelza/32/3026_2.png) [@georgelza](https://forum.confluent.io/u/georgelza)\
**Post date:** [21 April 2021 13:21 UTC](https://forum.confluent.io/t/golang-code-not-connecting-to-topic-when-containerised/1548/7 "2021-04-21T13:21:27Z")

</div>

Sweeeeeet, Mr Robin is my hero, again, thanks. that resolved that issue, hehehehe

now for me onto to the next one, having I think a similar problem between the docker running the Part 2 / scrubber program and the Part 3 Poster, but think I just need to find the correct K8S service name to utilise.

G

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/confluentcommunity/original/1X/c49438c90c9df282e9996fdf6971be890c71b65a.svg) [@system](https://forum.confluent.io/u/system)\
**Post date:** [28 April 2021 13:22 UTC](https://forum.confluent.io/t/golang-code-not-connecting-to-topic-when-containerised/1548/8 "2021-04-28T13:22:01Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
