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 | |
serkant.uluderya | b38671c | 2019-11-01 09:35:38 -0700 | [diff] [blame] | 21 | ca "github.com/opencord/voltha-protos/v3/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 |
Neha Sharma | dd9af39 | 2020-04-28 09:03:57 +0000 | [diff] [blame] | 42 | DefaultKafkaAddress = DefaultKafkaHost + ":" + string(DefaultKafkaPort) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 43 | DefaultGroupName = "voltha" |
| 44 | DefaultSleepOnError = 1 |
| 45 | DefaultProducerFlushFrequency = 10 |
| 46 | DefaultProducerFlushMessages = 10 |
| 47 | DefaultProducerFlushMaxmessages = 100 |
| 48 | DefaultProducerReturnSuccess = true |
| 49 | DefaultProducerReturnErrors = true |
| 50 | DefaultProducerRetryMax = 3 |
| 51 | DefaultProducerRetryBackoff = time.Millisecond * 100 |
| 52 | DefaultConsumerMaxwait = 100 |
| 53 | DefaultMaxProcessingTime = 100 |
| 54 | DefaultConsumerType = PartitionConsumer |
| 55 | DefaultNumberPartitions = 3 |
| 56 | DefaultNumberReplicas = 1 |
| 57 | DefaultAutoCreateTopic = false |
| 58 | DefaultMetadataMaxRetry = 3 |
Scott Baker | 104b67d | 2019-10-29 15:56:27 -0700 | [diff] [blame] | 59 | DefaultLivenessChannelInterval = time.Second * 30 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 60 | ) |
| 61 | |
| 62 | // MsgClient represents the set of APIs a Kafka MsgClient must implement |
| 63 | type Client interface { |
| 64 | Start() error |
| 65 | Stop() |
| 66 | CreateTopic(topic *Topic, numPartition int, repFactor int) error |
| 67 | DeleteTopic(topic *Topic) error |
| 68 | Subscribe(topic *Topic, kvArgs ...*KVArg) (<-chan *ca.InterContainerMessage, error) |
| 69 | UnSubscribe(topic *Topic, ch <-chan *ca.InterContainerMessage) error |
Scott Baker | 84a55ce | 2020-04-17 10:11:30 -0700 | [diff] [blame] | 70 | SubscribeForMetadata(func(fromTopic string, timestamp time.Time)) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 71 | Send(msg interface{}, topic *Topic, keys ...string) error |
Scott Baker | 104b67d | 2019-10-29 15:56:27 -0700 | [diff] [blame] | 72 | SendLiveness() error |
| 73 | EnableLivenessChannel(enable bool) chan bool |
Scott Baker | 0fef698 | 2019-12-12 09:49:42 -0800 | [diff] [blame] | 74 | EnableHealthinessChannel(enable bool) chan bool |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 75 | } |