Setting up Confluent Kafka Client for Golang with VSCode

mourya venkat
3 min readOct 27, 2019

--

This article is specifically for setting up your Editor to align with the newest confluent Kafka Go Client.

One may think what’s the big deal in this. Well, if that’s the thought, you gonna waste a day or two trying to set it up.

So what’s the big deal here. It’s just an other package import and function invocation right ???

As soon as you start working with kafka, you need a client package to talk to it. Till date people used Sarama(https://github.com/Shopify/sarama) as the go client which is an open sourced library written completely in GO.

But recently confluent(The actual maintainer of Kafka) had released this Go client Confluentic Kafka(https://github.com/confluentinc/confluent-kafka-go) as the official go package for kafka. So as its an official library we planned to move from sarama to confluentic.

Here comes the biggest problem for which I’ve spent one day to figure out the issue.

As soon as I tried cloning the package to my GOPATH using

go get -u gopkg.in/confluentinc/confluent-kafka-go.v1/kafka

and started building my test producer.

When I started building my producer I was not getting any auto suggestions by VSCode. This is a major drawback because without knowing what actually lies in each struct and without being redirected to the actual code where comments are written to make us understand each field’s importance, we can’t build our actual client.

I started referring to various sources as all my packages are giving recommendations except for this one confluent kafka. I started debugging various resources and tried checking the code base of Kafka and after scratching my head for a day and losing couple of hair strands I finally found the issue.

Confluent Kafka is Golang package which underneath uses C language modules by importing a package called ‘C’.

The problem with VSCode was unable to find an importted package it stops auto recommendations and suggestions.

The problem with this is that the inbuilt library uses a package called ‘C’ which cannot be imported and go compiler knows how to deal with it. But the poor VSCode was not able to get reference to the package. As a result it stopped recommending me auto suggestions.

This is how the code files in each the confluent-kafka-go package starts with

So what I’ve found out is that if you flip the unimported package to the top and all those importable package to the bottom, VSCode will start functioning again.

So in this way, I went on to each .go file written in confluent-kafka-go and then flipped the C import with the other imports.

Boom, the recommendation started working.

Do let me know in case if you are still facing issues over this.

--

--

mourya venkat
mourya venkat

Written by mourya venkat

I will starve to death if you don’t feed me some code. Quora : https://www.quora.com/profile/Mourya-Venkat-1

Responses (1)