blob: b3e20a3617632a00ad3d9d4bd1744a8d79b361f7 [file] [log] [blame]
khenaidoo7d3c5582021-08-11 18:09:44 -04001/*
Joey Armstrongacd8d182024-01-28 16:01:00 -05002* Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
khenaidoo7d3c5582021-08-11 18:09:44 -04003
Mahir Gunyel00554c62023-07-24 09:44:52 +03004* 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
khenaidoo7d3c5582021-08-11 18:09:44 -04007
Mahir Gunyel00554c62023-07-24 09:44:52 +03008* http://www.apache.org/licenses/LICENSE-2.0
khenaidoo7d3c5582021-08-11 18:09:44 -04009
Mahir Gunyel00554c62023-07-24 09:44:52 +030010* 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.
khenaidoo7d3c5582021-08-11 18:09:44 -040020 */
21package kafka
22
23import (
24 "context"
25 "time"
26
27 "github.com/golang/protobuf/proto"
28)
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 (
46 DefaultKafkaAddress = "127.0.0.1:9092"
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
63 DefaultMaxRetries = 3
64 DefaultLivenessChannelInterval = time.Second * 30
65)
66
67// MsgClient represents the set of APIs a Kafka MsgClient must implement
68type Client interface {
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
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
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
kesavand510a31c2022-03-16 17:12:12 +053080 ListTopics(ctx context.Context) ([]string, error)
khenaidoo7d3c5582021-08-11 18:09:44 -040081}