How to create a kafka message without producer?

Issue

I want to create a basic test case without bootstrapping producer, consumer and an instance of kafka for a test. I’m stuck with creating a basic message somehow and cannot find my error.
This is the struct definition from the confluent-kafka-go sdk:

// Message represents a Kafka message
type Message struct {
    TopicPartition TopicPartition
    Value          []byte
    Key            []byte
    Timestamp      time.Time
    TimestampType  TimestampType
    Opaque         interface{}
    Headers        []Header
}

My basic message creation looks like this.
I already verified that topicPartition struct and validImageUploadMessageAsBytes are valid objects.

kafkaMessage := kafka.Message{
        TopicPartition: topicPartition,
        Value:          validImageUploadMessageAsBytes,
        Key:            messageKey,
        Headers:        nil,
    }

I also tried the following approach to make sure it does not fail because of some data I provide into the message:

emptyMessage := new(kafka.Message)
    emptyMessage.TopicPartition = topicPartition
    emptyMessage.Value = []byte("")
    emptyMessage.Key = []byte("")

This example produces the same output as in the picture below

When debugging it the test with GoLand (2021.3.3) I am presented with this variable value

Failed to compute node presentation

Solution

The code is working properly, it is just a display issue by the IDE GoLand (2021.3.3)

Answered By – Anxifer

Answer Checked By – Dawn Plyler (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.