blob: eee96313765faa7f6f98aad7741e3002d7abea31 [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
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 */
16package kafka
17
18import (
dbainbri4d3a0dc2020-12-02 00:33:42 +000019 "context"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000020 "time"
David K. Bainbridged80007b2021-04-12 12:22:29 +000021
22 ca "github.com/opencord/voltha-protos/v4/go/inter_container"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000023)
24
25const (
26 PartitionConsumer = iota
27 GroupCustomer = iota
28)
29
30const (
31 OffsetNewest = -1
32 OffsetOldest = -2
33)
34
35const (
36 GroupIdKey = "groupId"
37 Offset = "offset"
38)
39
40const (
David K. Bainbridged80007b2021-04-12 12:22:29 +000041 DefaultKafkaAddress = "127.0.0.1:9092"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000042 DefaultGroupName = "voltha"
43 DefaultSleepOnError = 1
44 DefaultProducerFlushFrequency = 10
45 DefaultProducerFlushMessages = 10
46 DefaultProducerFlushMaxmessages = 100
47 DefaultProducerReturnSuccess = true
48 DefaultProducerReturnErrors = true
49 DefaultProducerRetryMax = 3
50 DefaultProducerRetryBackoff = time.Millisecond * 100
51 DefaultConsumerMaxwait = 100
52 DefaultMaxProcessingTime = 100
53 DefaultConsumerType = PartitionConsumer
54 DefaultNumberPartitions = 3
55 DefaultNumberReplicas = 1
56 DefaultAutoCreateTopic = false
57 DefaultMetadataMaxRetry = 3
58 DefaultLivenessChannelInterval = time.Second * 30
59)
60
61// MsgClient represents the set of APIs a Kafka MsgClient must implement
62type Client interface {
dbainbri4d3a0dc2020-12-02 00:33:42 +000063 Start(ctx context.Context) error
64 Stop(ctx context.Context)
65 CreateTopic(ctx context.Context, topic *Topic, numPartition int, repFactor int) error
66 DeleteTopic(ctx context.Context, topic *Topic) error
67 Subscribe(ctx context.Context, topic *Topic, kvArgs ...*KVArg) (<-chan *ca.InterContainerMessage, error)
68 UnSubscribe(ctx context.Context, topic *Topic, ch <-chan *ca.InterContainerMessage) error
69 SubscribeForMetadata(context.Context, func(fromTopic string, timestamp time.Time))
70 Send(ctx context.Context, msg interface{}, topic *Topic, keys ...string) error
71 SendLiveness(ctx context.Context) error
72 EnableLivenessChannel(ctx context.Context, enable bool) chan bool
73 EnableHealthinessChannel(ctx context.Context, enable bool) chan bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000074}