blob: 77c529bc53e371119ab9ed7fc542a64f9c338fe5 [file] [log] [blame]
Scott Baker2c1c4822019-10-16 11:02:41 -07001/*
Joey Armstrong9cdee9f2024-01-03 04:56:14 -05002* Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
Scott Baker2c1c4822019-10-16 11:02:41 -07003
Joey Armstrong7f8436c2023-07-09 20:23:27 -04004* 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 Baker2c1c4822019-10-16 11:02:41 -07007
Joey Armstrong7f8436c2023-07-09 20:23:27 -04008* http://www.apache.org/licenses/LICENSE-2.0
Scott Baker2c1c4822019-10-16 11:02:41 -07009
Joey Armstrong7f8436c2023-07-09 20:23:27 -040010* 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 Baker2c1c4822019-10-16 11:02:41 -070020 */
Akash Reddy Kankanala05aff182025-05-06 12:57:32 +053021//nolint:staticcheck
Scott Baker2c1c4822019-10-16 11:02:41 -070022package kafka
23
24import (
Neha Sharma94f16a92020-06-26 04:17:55 +000025 "context"
Neha Sharma94f16a92020-06-26 04:17:55 +000026 "time"
David K. Bainbridgec50d88c2021-04-08 15:47:03 +000027
khenaidoo26721882021-08-11 17:42:52 -040028 "github.com/golang/protobuf/proto"
Scott Baker2c1c4822019-10-16 11:02:41 -070029)
30
31const (
32 PartitionConsumer = iota
33 GroupCustomer = iota
34)
35
36const (
37 OffsetNewest = -1
38 OffsetOldest = -2
39)
40
41const (
42 GroupIdKey = "groupId"
43 Offset = "offset"
44)
45
46const (
David K. Bainbridgec50d88c2021-04-08 15:47:03 +000047 DefaultKafkaAddress = "127.0.0.1:9092"
Scott Baker2c1c4822019-10-16 11:02:41 -070048 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
khenaidoo26721882021-08-11 17:42:52 -040064 DefaultMaxRetries = 3
Scott Baker104b67d2019-10-29 15:56:27 -070065 DefaultLivenessChannelInterval = time.Second * 30
Scott Baker2c1c4822019-10-16 11:02:41 -070066)
67
68// MsgClient represents the set of APIs a Kafka MsgClient must implement
69type Client interface {
Neha Sharma94f16a92020-06-26 04:17:55 +000070 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
khenaidoo26721882021-08-11 17:42:52 -040074 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 Sharma94f16a92020-06-26 04:17:55 +000076 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
kesavandd85e52b2022-03-15 16:38:08 +053081 ListTopics(ctx context.Context) ([]string, error)
Scott Baker2c1c4822019-10-16 11:02:41 -070082}