khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [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 ( |
khenaidoo | 4c1a5bf | 2018-11-29 15:53:42 -0500 | [diff] [blame] | 19 | "time" |
Abhilash S.L | 294ff52 | 2019-06-26 18:14:33 +0530 | [diff] [blame] | 20 | |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 21 | ca "github.com/opencord/voltha-protos/v3/go/inter_container" |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | const ( |
khenaidoo | 4c1a5bf | 2018-11-29 15:53:42 -0500 | [diff] [blame] | 25 | PartitionConsumer = iota |
| 26 | GroupCustomer = iota |
| 27 | ) |
| 28 | |
| 29 | const ( |
khenaidoo | 731697e | 2019-01-29 16:03:29 -0500 | [diff] [blame] | 30 | OffsetNewest = -1 |
| 31 | OffsetOldest = -2 |
| 32 | ) |
| 33 | |
| 34 | const ( |
khenaidoo | ca30132 | 2019-01-09 23:06:32 -0500 | [diff] [blame] | 35 | GroupIdKey = "groupId" |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 36 | Offset = "offset" |
khenaidoo | ca30132 | 2019-01-09 23:06:32 -0500 | [diff] [blame] | 37 | ) |
| 38 | |
| 39 | const ( |
khenaidoo | 4c1a5bf | 2018-11-29 15:53:42 -0500 | [diff] [blame] | 40 | DefaultKafkaHost = "127.0.0.1" |
| 41 | DefaultKafkaPort = 9092 |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 42 | DefaultKafkaAddress = DefaultKafkaHost + ":" + string(DefaultKafkaPort) |
khenaidoo | ca30132 | 2019-01-09 23:06:32 -0500 | [diff] [blame] | 43 | DefaultGroupName = "voltha" |
khenaidoo | 4c1a5bf | 2018-11-29 15:53:42 -0500 | [diff] [blame] | 44 | DefaultSleepOnError = 1 |
khenaidoo | 8f47419 | 2019-04-03 17:20:44 -0400 | [diff] [blame] | 45 | DefaultProducerFlushFrequency = 10 |
| 46 | DefaultProducerFlushMessages = 10 |
| 47 | DefaultProducerFlushMaxmessages = 100 |
khenaidoo | 9084792 | 2018-12-03 14:47:51 -0500 | [diff] [blame] | 48 | DefaultProducerReturnSuccess = true |
khenaidoo | 4c1a5bf | 2018-11-29 15:53:42 -0500 | [diff] [blame] | 49 | DefaultProducerReturnErrors = true |
| 50 | DefaultProducerRetryMax = 3 |
| 51 | DefaultProducerRetryBackoff = time.Millisecond * 100 |
khenaidoo | 8f47419 | 2019-04-03 17:20:44 -0400 | [diff] [blame] | 52 | DefaultConsumerMaxwait = 100 |
khenaidoo | 4c1a5bf | 2018-11-29 15:53:42 -0500 | [diff] [blame] | 53 | DefaultMaxProcessingTime = 100 |
| 54 | DefaultConsumerType = PartitionConsumer |
| 55 | DefaultNumberPartitions = 3 |
| 56 | DefaultNumberReplicas = 1 |
| 57 | DefaultAutoCreateTopic = false |
Abhilash S.L | 294ff52 | 2019-06-26 18:14:33 +0530 | [diff] [blame] | 58 | DefaultMetadataMaxRetry = 3 |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 59 | DefaultLivenessChannelInterval = time.Second * 30 |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 60 | ) |
| 61 | |
| 62 | // MsgClient represents the set of APIs a Kafka MsgClient must implement |
| 63 | type Client interface { |
khenaidoo | 4c1a5bf | 2018-11-29 15:53:42 -0500 | [diff] [blame] | 64 | Start() error |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 65 | Stop() |
khenaidoo | 4c1a5bf | 2018-11-29 15:53:42 -0500 | [diff] [blame] | 66 | CreateTopic(topic *Topic, numPartition int, repFactor int) error |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 67 | DeleteTopic(topic *Topic) error |
khenaidoo | ca30132 | 2019-01-09 23:06:32 -0500 | [diff] [blame] | 68 | Subscribe(topic *Topic, kvArgs ...*KVArg) (<-chan *ca.InterContainerMessage, error) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 69 | UnSubscribe(topic *Topic, ch <-chan *ca.InterContainerMessage) error |
Scott Baker | 504b480 | 2020-04-17 10:12:20 -0700 | [diff] [blame] | 70 | SubscribeForMetadata(func(fromTopic string, timestamp time.Time)) |
khenaidoo | 4c1a5bf | 2018-11-29 15:53:42 -0500 | [diff] [blame] | 71 | Send(msg interface{}, topic *Topic, keys ...string) error |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 72 | SendLiveness() error |
| 73 | EnableLivenessChannel(enable bool) chan bool |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 74 | EnableHealthinessChannel(enable bool) chan bool |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 75 | } |