mirror of
https://github.com/go-micro/go-micro.git
synced 2025-04-11 11:02:02 +02:00
* Add Kafka asynchronous send support * Add Kafka asynchronous send support * Upgrade sarama to 1.30.1 * Example
25 lines
524 B
Markdown
25 lines
524 B
Markdown
# Kafka Broker
|
|
|
|
|
|
## Async Publish
|
|
```go
|
|
import "github.com/Shopify/sarama"
|
|
|
|
func AsyncProduceMessage() {
|
|
var errorsChan = make(chan *sarama.ProducerError)
|
|
var successesChan = make(chan *sarama.ProducerMessage)
|
|
go func() {
|
|
for err := range errorsChan {
|
|
fmt.Println(err)
|
|
}
|
|
}
|
|
go func() {
|
|
for v := range successesChan {
|
|
fmt.Println(v)
|
|
}
|
|
}
|
|
b := NewBroker(AsyncProducer(errorsChan,successesChan))
|
|
b.Publish(`topic`, &broker.Message{})
|
|
}
|
|
```
|