github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/subscriber/common/consumer/consumer.go (about) 1 // Copyright (c) 2017-2018 Uber Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package consumer 16 17 import "io" 18 19 // Message is a single message pulled off a Kafka topic. 20 type Message interface { 21 // Key is a mutable reference to the message's key. 22 Key() []byte 23 // Value is a mutable reference to the message's value. 24 Value() []byte 25 // Topic is the topic from which the message was read. 26 Topic() string 27 // Partition is the ID of the partition from which the message was read. 28 Partition() int32 29 // Offset is the message's offset. 30 Offset() int64 31 // Ack the message 32 Ack() 33 // Nack the message 34 Nack() 35 // Cluster is the message's originated cluster. 36 Cluster() string 37 } 38 39 // A Consumer allows users to read and process messages from a Kafka topic. 40 // Consumer processes within the same group use ZooKeeper to negotiate partition 41 // ownership, so each process sees a stream of messages from one or more 42 // partitions. Within a partition, messages are linearizable. 43 type Consumer interface { 44 io.Closer 45 46 // Name returns the name of this consumer group. 47 Name() string 48 // Topics returns the names of the topics being consumed. 49 Topics() []string 50 // Errors returns a channel of errors for the topic. To prevent deadlocks, 51 // users must read from the error channel. 52 // 53 // All errors returned from this channel can be safely cast to the 54 // consumer.Error interface, which allows structured access to the topic 55 // name and partition number. 56 Errors() <-chan error 57 // Closed returns a channel that unblocks when the consumer successfully shuts 58 // down. 59 Closed() <-chan struct{} 60 // Messages returns a channel of messages for the topic. 61 // 62 // If the consumer is not configured with nonzero buffer size, the Errors() 63 // channel must be read in conjunction with Messages() to prevent deadlocks. 64 Messages() <-chan Message 65 // CommitUpTo marks this message and all previous messages in the same partition 66 // as processed. The last processed offset for each partition is periodically 67 // flushed to ZooKeeper; on startup, consumers begin processing after the last 68 // stored offset. 69 CommitUpTo(Message) error 70 }