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