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

Fix error handling and partition config bugs in KafkaMessagingProvide… #5527

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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 @@ -41,6 +41,8 @@ case class KafkaConfig(replicationFactor: Short, consumerLagCheckInterval: Finit
object KafkaMessagingProvider extends MessagingProvider {
import KafkaConfiguration._

private val topicPartitionsConfigKey = "partitions"

def getConsumer(config: WhiskConfig, groupId: String, topic: String, maxPeek: Int, maxPollInterval: FiniteDuration)(
implicit logging: Logging,
actorSystem: ActorSystem): MessageConsumer =
Expand All @@ -64,12 +66,13 @@ object KafkaMessagingProvider extends MessagingProvider {

Try(AdminClient.create(commonConfig + (AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG -> config.kafkaHosts)))
.flatMap(client => {
val partitions = topicConfig.getOrElse("partitions", "1").toInt
val nt = new NewTopic(topic, partitions, kafkaConfig.replicationFactor).configs(topicConfig.asJava)
val partitions = topicConfig.getOrElse(topicPartitionsConfigKey, "1").toInt
val safeTopicConfig = topicConfig - topicPartitionsConfigKey
val nt = new NewTopic(topic, partitions, kafkaConfig.replicationFactor).configs(safeTopicConfig.asJava)

def createTopic(retries: Int = 5): Try[Unit] = {
Try(client.listTopics().names().get())
.map(topics =>
.flatMap(topics =>
if (topics.contains(topic)) {
Success(logging.info(this, s"$topic already exists and the user can see it, skipping creation."))
} else {
Expand Down
Loading