MCPcopy
hub / github.com/IBM/sarama / ExampleSyncProducer

Function ExampleSyncProducer

sync_producer_test.go:333–351  ·  view source on GitHub ↗

This example shows the basic usage pattern of the SyncProducer.

()

Source from the content-addressed store, hash-verified

331
332// This example shows the basic usage pattern of the SyncProducer.
333func ExampleSyncProducer() {
334 producer, err := NewSyncProducer([]string{"localhost:9092"}, nil)
335 if err != nil {
336 log.Fatalln(err)
337 }
338 defer func() {
339 if err := producer.Close(); err != nil {
340 log.Fatalln(err)
341 }
342 }()
343
344 msg := &ProducerMessage{Topic: "my_topic", Value: StringEncoder("testing 123")}
345 partition, offset, err := producer.SendMessage(msg)
346 if err != nil {
347 log.Printf("FAILED to send message: %s\n", err)
348 } else {
349 log.Printf("> message sent to partition %d at offset %d\n", partition, offset)
350 }
351}

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.95
SendMessageMethod · 0.95
StringEncoderTypeAlias · 0.85
NewSyncProducerFunction · 0.70
PrintfMethod · 0.65

Tested by

no test coverage detected