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

Handle non-existent topics in partitionsFor #456

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,11 @@ object Consumer {
} yield result
}

def partitions1(f: => ListJ[PartitionInfoJ]) = {
def partitions1(f: => Option[ListJ[PartitionInfoJ]]) = {
for {
result <- serialBlocking { f }
result <- partitionsInfoListF[F](result)
} yield result
result <- result.traverse(partitionsInfoListF[F])
} yield result.getOrElse(List.empty)
}

def topics1(f: => MapJ[Topic, ListJ[PartitionInfoJ]]) = {
Expand Down Expand Up @@ -506,11 +506,11 @@ object Consumer {
}

def partitions(topic: Topic) = {
partitions1 { consumer.partitionsFor(topic) }
partitions1 { Option(consumer.partitionsFor(topic)) }
}

def partitions(topic: Topic, timeout: FiniteDuration) = {
partitions1 { consumer.partitionsFor(topic, timeout.asJava) }
partitions1 { Option(consumer.partitionsFor(topic, timeout.asJava)) }
}

val topics = topics1 { consumer.listTopics() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.time.Instant
import java.util.{Map => MapJ}

import cats.data.{NonEmptyMap => Nem, NonEmptySet => Nes}
import cats.implicits.toTraverseOps
import com.evolutiongaming.skafka.Converters._
import com.evolutiongaming.skafka.consumer.ConsumerConverters._
import com.evolutiongaming.skafka._
Expand Down Expand Up @@ -217,15 +218,15 @@ object RebalanceConsumer {

def partitionsFor(topic: Topic) =
for {
a <- Try { c.partitionsFor(topic) }
a <- partitionsInfoListF[Try](a)
} yield a
a <- Try { Option(c.partitionsFor(topic)) }
a <- a.traverse(partitionsInfoListF[Try])
} yield a.getOrElse(List.empty)

def partitionsFor(topic: Topic, timeout: FiniteDuration) =
for {
a <- Try { c.partitionsFor(topic, timeout.asJava) }
a <- partitionsInfoListF[Try](a)
} yield a
a <- Try { Option(c.partitionsFor(topic, timeout.asJava)) }
a <- a.traverse(partitionsInfoListF[Try])
} yield a.getOrElse(List.empty)

def paused() =
for {
Expand Down
Loading