blob: fdc05bc6e44300c06a053ef8d33c5fe201fbeb35 [file] [log] [blame]
khenaidood948f772021-08-11 17:49:24 -04001/*
2 * Copyright 2018-present Open Networking Foundation
3
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
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
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.
20 */
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
80}