-
Notifications
You must be signed in to change notification settings - Fork 97
/
KafkaSubscription.scala
51 lines (42 loc) · 1.61 KB
/
KafkaSubscription.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Copyright 2018-2022 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
package fs2.kafka.consumer
import cats.Reducible
import cats.data.NonEmptyList
import scala.util.matching.Regex
trait KafkaSubscription[F[_]] {
/**
* Subscribes the consumer to the specified topics. Note that you have to
* use one of the `subscribe` functions to subscribe to one or more topics
* before using any of the provided `Stream`s, or a [[NotSubscribedException]]
* will be raised in the `Stream`s.
*/
def subscribeTo(firstTopic: String, remainingTopics: String*): F[Unit] =
subscribe(NonEmptyList.of(firstTopic, remainingTopics: _*))
/**
* Subscribes the consumer to the specified topics. Note that you have to
* use one of the `subscribe` functions to subscribe to one or more topics
* before using any of the provided `Stream`s, or a [[NotSubscribedException]]
* will be raised in the `Stream`s.
*
* @param topics the topics to which the consumer should subscribe
*/
def subscribe[G[_]: Reducible](topics: G[String]): F[Unit]
/**
* Subscribes the consumer to the topics matching the specified `Regex`.
* Note that you have to use one of the `subscribe` functions before you
* can use any of the provided `Stream`s, or a [[NotSubscribedException]]
* will be raised in the `Stream`s.
*
* @param regex the regex to which matching topics should be subscribed
*/
def subscribe(regex: Regex): F[Unit]
/**
* Unsubscribes the consumer from all topics and partitions assigned
* by `subscribe` or `assign`.
*/
def unsubscribe: F[Unit]
}