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