Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1 | /* |
Joey Armstrong | 9cdee9f | 2024-01-03 04:56:14 -0500 | [diff] [blame] | 2 | * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 3 | |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 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 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 7 | |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 9 | |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 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 | * |
| 17 | * NOTE: The kafka client is used to publish events on Kafka in voltha |
| 18 | * release 2.9. It is no longer used for inter voltha container |
| 19 | * communication. |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 20 | */ |
Akash Reddy Kankanala | 05aff18 | 2025-05-06 12:57:32 +0530 | [diff] [blame^] | 21 | //nolint:staticcheck |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 22 | package kafka |
| 23 | |
| 24 | import ( |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 25 | "context" |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 26 | "time" |
David K. Bainbridge | c50d88c | 2021-04-08 15:47:03 +0000 | [diff] [blame] | 27 | |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 28 | "github.com/golang/protobuf/proto" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 29 | ) |
| 30 | |
| 31 | const ( |
| 32 | PartitionConsumer = iota |
| 33 | GroupCustomer = iota |
| 34 | ) |
| 35 | |
| 36 | const ( |
| 37 | OffsetNewest = -1 |
| 38 | OffsetOldest = -2 |
| 39 | ) |
| 40 | |
| 41 | const ( |
| 42 | GroupIdKey = "groupId" |
| 43 | Offset = "offset" |
| 44 | ) |
| 45 | |
| 46 | const ( |
David K. Bainbridge | c50d88c | 2021-04-08 15:47:03 +0000 | [diff] [blame] | 47 | DefaultKafkaAddress = "127.0.0.1:9092" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 48 | DefaultGroupName = "voltha" |
| 49 | DefaultSleepOnError = 1 |
| 50 | DefaultProducerFlushFrequency = 10 |
| 51 | DefaultProducerFlushMessages = 10 |
| 52 | DefaultProducerFlushMaxmessages = 100 |
| 53 | DefaultProducerReturnSuccess = true |
| 54 | DefaultProducerReturnErrors = true |
| 55 | DefaultProducerRetryMax = 3 |
| 56 | DefaultProducerRetryBackoff = time.Millisecond * 100 |
| 57 | DefaultConsumerMaxwait = 100 |
| 58 | DefaultMaxProcessingTime = 100 |
| 59 | DefaultConsumerType = PartitionConsumer |
| 60 | DefaultNumberPartitions = 3 |
| 61 | DefaultNumberReplicas = 1 |
| 62 | DefaultAutoCreateTopic = false |
| 63 | DefaultMetadataMaxRetry = 3 |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 64 | DefaultMaxRetries = 3 |
Scott Baker | 104b67d | 2019-10-29 15:56:27 -0700 | [diff] [blame] | 65 | DefaultLivenessChannelInterval = time.Second * 30 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 66 | ) |
| 67 | |
| 68 | // MsgClient represents the set of APIs a Kafka MsgClient must implement |
| 69 | type Client interface { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 70 | Start(ctx context.Context) error |
| 71 | Stop(ctx context.Context) |
| 72 | CreateTopic(ctx context.Context, topic *Topic, numPartition int, repFactor int) error |
| 73 | DeleteTopic(ctx context.Context, topic *Topic) error |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 74 | Subscribe(ctx context.Context, topic *Topic, kvArgs ...*KVArg) (<-chan proto.Message, error) |
| 75 | UnSubscribe(ctx context.Context, topic *Topic, ch <-chan proto.Message) error |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 76 | SubscribeForMetadata(context.Context, func(fromTopic string, timestamp time.Time)) |
| 77 | Send(ctx context.Context, msg interface{}, topic *Topic, keys ...string) error |
| 78 | SendLiveness(ctx context.Context) error |
| 79 | EnableLivenessChannel(ctx context.Context, enable bool) chan bool |
| 80 | EnableHealthinessChannel(ctx context.Context, enable bool) chan bool |
kesavand | d85e52b | 2022-03-15 16:38:08 +0530 | [diff] [blame] | 81 | ListTopics(ctx context.Context) ([]string, error) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 82 | } |