This commit is contained in:
crusader 2018-05-11 19:06:30 +09:00
parent a7922fda42
commit fedd128649
2 changed files with 9 additions and 1 deletions

View File

@ -4,6 +4,8 @@ import (
"fmt"
"strings"
"sync/atomic"
"github.com/segmentio/kafka-go"
)
type ConsumerHandler interface {
@ -17,6 +19,8 @@ type ConsumerHandler interface {
OnStop(consumerCtx ConsumerCtx)
Destroy(consumerCtx ConsumerCtx)
OnMessage(msg *kafka.Message)
Validate() error
}
@ -47,6 +51,10 @@ func (ch *ConsumerHandlers) Destroy(consumerCtx ConsumerCtx) {
}
func (ch *ConsumerHandlers) OnMessage(msg *kafka.Message) {
fmt.Printf("message at topic/partition/offset %v/%v/%v: %s = %s\n", msg.Topic, msg.Partition, msg.Offset, string(msg.Key), string(msg.Value))
}
func (ch *ConsumerHandlers) GetName() string {
return ch.Name
}

View File

@ -140,7 +140,7 @@ func (c *Consumer) handleReceive(stopChan <-chan struct{}, doneChan chan<- error
continue
}
fmt.Printf("message at topic/partition/offset %v/%v/%v: %s = %s\n", m.Topic, m.Partition, m.Offset, string(m.Key), string(m.Value))
c.ConsumerHandler.OnMessage(&m)
}
}