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 | */ |
| 21 | package kafka |
| 22 | |
| 23 | import ( |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 24 | "context" |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 25 | "time" |
David K. Bainbridge | c50d88c | 2021-04-08 15:47:03 +0000 | [diff] [blame] | 26 | |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 27 | "github.com/golang/protobuf/proto" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | const ( |
| 31 | PartitionConsumer = iota |
| 32 | GroupCustomer = iota |
| 33 | ) |
| 34 | |
| 35 | const ( |
| 36 | OffsetNewest = -1 |
| 37 | OffsetOldest = -2 |
| 38 | ) |
| 39 | |
| 40 | const ( |
| 41 | GroupIdKey = "groupId" |
| 42 | Offset = "offset" |
| 43 | ) |
| 44 | |
| 45 | const ( |
David K. Bainbridge | c50d88c | 2021-04-08 15:47:03 +0000 | [diff] [blame] | 46 | DefaultKafkaAddress = "127.0.0.1:9092" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 47 | DefaultGroupName = "voltha" |
| 48 | DefaultSleepOnError = 1 |
| 49 | DefaultProducerFlushFrequency = 10 |
| 50 | DefaultProducerFlushMessages = 10 |
| 51 | DefaultProducerFlushMaxmessages = 100 |
| 52 | DefaultProducerReturnSuccess = true |
| 53 | DefaultProducerReturnErrors = true |
| 54 | DefaultProducerRetryMax = 3 |
| 55 | DefaultProducerRetryBackoff = time.Millisecond * 100 |
| 56 | DefaultConsumerMaxwait = 100 |
| 57 | DefaultMaxProcessingTime = 100 |
| 58 | DefaultConsumerType = PartitionConsumer |
| 59 | DefaultNumberPartitions = 3 |
| 60 | DefaultNumberReplicas = 1 |
| 61 | DefaultAutoCreateTopic = false |
| 62 | DefaultMetadataMaxRetry = 3 |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 63 | DefaultMaxRetries = 3 |
Scott Baker | 104b67d | 2019-10-29 15:56:27 -0700 | [diff] [blame] | 64 | DefaultLivenessChannelInterval = time.Second * 30 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 65 | ) |
| 66 | |
| 67 | // MsgClient represents the set of APIs a Kafka MsgClient must implement |
| 68 | type Client interface { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 69 | Start(ctx context.Context) error |
| 70 | Stop(ctx context.Context) |
| 71 | CreateTopic(ctx context.Context, topic *Topic, numPartition int, repFactor int) error |
| 72 | DeleteTopic(ctx context.Context, topic *Topic) error |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 73 | Subscribe(ctx context.Context, topic *Topic, kvArgs ...*KVArg) (<-chan proto.Message, error) |
| 74 | UnSubscribe(ctx context.Context, topic *Topic, ch <-chan proto.Message) error |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 75 | SubscribeForMetadata(context.Context, func(fromTopic string, timestamp time.Time)) |
| 76 | Send(ctx context.Context, msg interface{}, topic *Topic, keys ...string) error |
| 77 | SendLiveness(ctx context.Context) error |
| 78 | EnableLivenessChannel(ctx context.Context, enable bool) chan bool |
| 79 | EnableHealthinessChannel(ctx context.Context, enable bool) chan bool |
kesavand | d85e52b | 2022-03-15 16:38:08 +0530 | [diff] [blame] | 80 | ListTopics(ctx context.Context) ([]string, error) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 81 | } |