Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deleteConsumerGroups method #730

Merged
merged 4 commits into from
Jan 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions modules/core/src/main/scala/fs2/kafka/KafkaAdminClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ sealed abstract class KafkaAdminClient[F[_]] {
*/
def listConsumerGroups: ListConsumerGroups[F]

/**
* Delete consumer groups from the cluster.
*/
def deleteConsumerGroups(groupIds: List[String]): F[Unit]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change this to:

def deleteConsumerGroups[G[_]](groupIds: G[String])(
  implicit G: Foldable[G]
): F[Unit]

to match the other functions?


/**
* Lists topics. Returns topic names using:
*
Expand Down Expand Up @@ -478,6 +483,12 @@ object KafkaAdminClient {
): F[Unit] =
withAdminClient(_.deleteConsumerGroupOffsets(groupId, partitions.asJava).all().void)

private[this] def deleteConsumerGroupsWith[F[_]](
withAdminClient: WithAdminClient[F],
groupIds: List[String]
): F[Unit] =
withAdminClient(_.deleteConsumerGroups(groupIds.asJava).all().void)

/**
* Creates a new [[KafkaAdminClient]] in the `Resource` context,
* using the specified [[AdminClientSettings]]. If working in a
Expand Down Expand Up @@ -580,6 +591,11 @@ object KafkaAdminClient {
): F[Unit] =
deleteConsumerGroupOffsetsWith(client, groupId, partitions)

override def deleteConsumerGroups(
groupIds: List[String]
): F[Unit] =
deleteConsumerGroupsWith(client, groupIds)

override def toString: String =
"KafkaAdminClient$" + System.identityHashCode(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ final class KafkaAdminClientSpec extends BaseKafkaSpec {
val expected = consumerGroupOffsetsMap - partition0
assert(res == expected)
}
_ <- adminClient
.deleteConsumerGroups(consumerGroupIds)
_ <- adminClient.listConsumerGroups.groupIds.map { res =>
val expected = List.empty
assert(res == expected)
}
} yield ()
}
.unsafeRunSync()
Expand Down