英文:
How to create a kafka message without producer?
问题
我想创建一个基本的测试用例,而不需要为测试创建生产者、消费者和Kafka实例。我在创建基本消息时遇到了问题,无法找到错误所在。
这是来自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
}
我的基本消息创建如下所示。我已经验证了topicPartition结构和validImageUploadMessageAsBytes是有效的对象。
kafkaMessage := kafka.Message{
TopicPartition: topicPartition,
Value: validImageUploadMessageAsBytes,
Key: messageKey,
Headers: nil,
}
我还尝试了以下方法,以确保它不会因为我提供的某些数据而失败:
emptyMessage := new(kafka.Message)
emptyMessage.TopicPartition = topicPartition
emptyMessage.Value = []byte("")
emptyMessage.Key = []byte("")
这个示例产生了与下图中相同的输出。
在使用GoLand(2021.3.3)调试测试时,我看到了这个变量的值:
英文:
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
答案1
得分: 1
代码正常工作,只是由于IDE GoLand(2021.3.3)的显示问题。
英文:
The code is working properly, it is just a display issue by the IDE GoLand (2021.3.3)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论