Skip to content

Make EmbeddedKafkaConfig a trait to allow other implementation #85

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

Merged
merged 2 commits into from
Sep 25, 2017

Conversation

max5599
Copy link
Contributor

@max5599 max5599 commented Sep 15, 2017

I'm using Kafka and a schema registry to serialize messages.
I've made a trait that allow me to run a Kafka and a schema registry:

trait EmbeddedKafkaAndSchemaRegistrySupport extends EmbeddedKafka {
  this: Suite =>

  def withRunningKafkaAndSchemaRegistry[T](block: (ConfluentConfig) => T): T = {
    implicit val kafkaConfig: EmbeddedKafkaConfig = new EmbeddedKafkaConfig(zooKeeperPort = getEphemeralPort, kafkaPort = getEphemeralPort)
    EmbeddedKafka.start()
    try {
      val confluentConfig = ConfluentConfig(kafkaConfig, schemaRegistryPort = getEphemeralPort)
      val schemaRegistry = startSchemaRegistry(confluentConfig)
      try {
        block(confluentConfig)
      } finally {
        schemaRegistry.stop()
      }
    } finally {
      EmbeddedKafka.stop()
    }
  }
}

case class ConfluentConfig(embeddedKafkaConfig: EmbeddedKafkaConfig, schemaRegistryPort : Int)

ConfluentConfig can't extend EmbeddedKafkaConfig because it's a case class so when using 'withRunningKafkaAndSchemaRegistry' I have to declare the implicit EmbeddedKafkaConfig:

withRunningKafkaAndSchemaRegistryAndImpressionEventSerializer { implicit config => implicit serializer =>
      implicit val kafkaConfig: EmbeddedKafkaConfig = config.embeddedKafkaConfig
      publishToKafka("topic", impressionEvent)
      ...
}

I'd like to make EmbeddedKafkaConfig a trait then make ConfluentConfig implements it to avoid declaring each time the EmbeddedKafkaConfig.
Does it make sense? Maybe there's another solution?
I've tried with implicit conversion but without success.
If that make sense I'll make the modifications then a pull request.

@manub
Copy link
Owner

manub commented Aug 20, 2017

Is ConfluentConfig a class provided by Confluent? If that's the case you could overload that method and have another version that works with ConfluentConfig.

@max5599
Copy link
Contributor Author

max5599 commented Sep 10, 2017

ConfluentConfig is a class I made that wrap EmbeddedKafkaConfig and the schema registry port.
So if a trait exists, I can extend it.
PS: sorry for the late answer

@manub
Copy link
Owner

manub commented Sep 11, 2017

That's ok - feel free to submit a PR for this!

customProducerProperties: Map[String, String] = Map.empty,
customConsumerProperties: Map[String, String] = Map.empty)
trait EmbeddedKafkaConfig {
val kafkaPort: Int
Copy link
Owner

Choose a reason for hiding this comment

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

@manub manub merged commit 7884e82 into manub:master Sep 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants