blob: b3e20a3617632a00ad3d9d4bd1744a8d79b361f7 [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 */
21package kafka
22
23import (
Neha Sharma94f16a92020-06-26 04:17:55 +000024 "context"
Neha Sharma94f16a92020-06-26 04:17:55 +000025 "time"
David K. Bainbridgec50d88c2021-04-08 15:47:03 +000026
khenaidoo26721882021-08-11 17:42:52 -040027 "github.com/golang/protobuf/proto"
Scott Baker2c1c4822019-10-16 11:02:41 -070028)
29
30const (
31 PartitionConsumer = iota
32 GroupCustomer = iota
33)
34
35const (
36 OffsetNewest = -1
37 OffsetOldest = -2
38)
39
40const (
41 GroupIdKey = "groupId"
42 Offset = "offset"
43)
44
45const (
David K. Bainbridgec50d88c2021-04-08 15:47:03 +000046 DefaultKafkaAddress = "127.0.0.1:9092"
Scott Baker2c1c4822019-10-16 11:02:41 -070047 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
khenaidoo26721882021-08-11 17:42:52 -040063 DefaultMaxRetries = 3
Scott Baker104b67d2019-10-29 15:56:27 -070064 DefaultLivenessChannelInterval = time.Second * 30
Scott Baker2c1c4822019-10-16 11:02:41 -070065)
66
67// MsgClient represents the set of APIs a Kafka MsgClient must implement
68type Client interface {
Neha Sharma94f16a92020-06-26 04:17:55 +000069 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
khenaidoo26721882021-08-11 17:42:52 -040073 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 Sharma94f16a92020-06-26 04:17:55 +000075 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
kesavandd85e52b2022-03-15 16:38:08 +053080 ListTopics(ctx context.Context) ([]string, error)
Scott Baker2c1c4822019-10-16 11:02:41 -070081}