Member-only story

Real-Time Trading App: Golang, Kafka, Websockets — Setting up Kafka in Golang (PART-2)

Kamalesh D
6 min readDec 19, 2023

Configuring Kafka in a Golang environment and creating a build file for the producer.

golang kafka

This marks Part 2 of our real-time trade app series in Golang. In this installment, we’ll dive into coding for Kafka, focusing on establishing a connection and creating a producer build file. This step is crucial for testing the API connection to Binance’s web sockets. Stay tuned for hands-on coding and insights into optimizing the integration!

Establishing a connection with the data source.

As previously noted, we’ll utilize Binance’s WebSocket API as our data source. Within your app folder, create a trades subfolder and include the following files: listener.go, publish.go, and ticker.go.

kafka golang

Ticker.go

  • Within ticker.go, you’ll find the model for the ticker data sourced from Binance. This model serves a dual purpose, as it will be employed for both receiving and publishing the data.
package trades

type Ticker struct {
Symbol string `json:"s"`
Price string `json:"p"`
Quantity string

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Kamalesh D
Kamalesh D

Written by Kamalesh D

DevOps and Cloud Enthusiast | Cyber Security | DevSecOps Engineer@FordMotors | https://dev.to/kamaleshseervi

Responses (1)

Write a response

would it be better rather than spawninga new go routine each time, spawn only one to process here? `convertAndPublishToKafka(trade)`