Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package kafka |
| 17 | |
| 18 | import ( |
| 19 | "time" |
| 20 | |
Scott Baker | f1b096c | 2019-11-01 12:36:30 -0700 | [diff] [blame] | 21 | ca "github.com/opencord/voltha-protos/v2/go/inter_container" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | const ( |
| 25 | PartitionConsumer = iota |
| 26 | GroupCustomer = iota |
| 27 | ) |
| 28 | |
| 29 | const ( |
| 30 | OffsetNewest = -1 |
| 31 | OffsetOldest = -2 |
| 32 | ) |
| 33 | |
| 34 | const ( |
| 35 | GroupIdKey = "groupId" |
| 36 | Offset = "offset" |
| 37 | ) |
| 38 | |
| 39 | const ( |
| 40 | DefaultKafkaHost = "127.0.0.1" |
| 41 | DefaultKafkaPort = 9092 |
| 42 | DefaultGroupName = "voltha" |
| 43 | DefaultSleepOnError = 1 |
| 44 | DefaultProducerFlushFrequency = 10 |
| 45 | DefaultProducerFlushMessages = 10 |
| 46 | DefaultProducerFlushMaxmessages = 100 |
| 47 | DefaultProducerReturnSuccess = true |
| 48 | DefaultProducerReturnErrors = true |
| 49 | DefaultProducerRetryMax = 3 |
| 50 | DefaultProducerRetryBackoff = time.Millisecond * 100 |
| 51 | DefaultConsumerMaxwait = 100 |
| 52 | DefaultMaxProcessingTime = 100 |
| 53 | DefaultConsumerType = PartitionConsumer |
| 54 | DefaultNumberPartitions = 3 |
| 55 | DefaultNumberReplicas = 1 |
| 56 | DefaultAutoCreateTopic = false |
| 57 | DefaultMetadataMaxRetry = 3 |
| 58 | ) |
| 59 | |
| 60 | // MsgClient represents the set of APIs a Kafka MsgClient must implement |
| 61 | type Client interface { |
| 62 | Start() error |
| 63 | Stop() |
| 64 | CreateTopic(topic *Topic, numPartition int, repFactor int) error |
| 65 | DeleteTopic(topic *Topic) error |
| 66 | Subscribe(topic *Topic, kvArgs ...*KVArg) (<-chan *ca.InterContainerMessage, error) |
| 67 | UnSubscribe(topic *Topic, ch <-chan *ca.InterContainerMessage) error |
| 68 | Send(msg interface{}, topic *Topic, keys ...string) error |
| 69 | } |