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

Allow to start Kafka and Schema Registry containers in the same Network #266

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

slawomirkania
Copy link

As a Developer I want to be able to start Kafka and Schema Registry in the same network using public interfaces/constructors.

Now it is impossible for two reasons:

  1. starting the Kafka container and invoking its getNetwork method results in a null response
  2. Schema Registry constructor does not allow to provide Network

Example usage

  final case class KafkaConfig(bootstrapServers: String, networkAlias: String)
  final case class SchemaRegistryConfig(schemaUrl: String)

  private def kafka(network: Network) =
    Resource
      .make(IO(KafkaContainer.Def(network).start()))(c => IO(c.stop()))
      .map { kafkaContainer =>
        KafkaConfig(kafkaContainer.bootstrapServers, kafkaContainer.networkAliases.head)
      }

  private def schemaRegistry(network: Network, kafkaConfig: KafkaConfig) =
    Resource
      .make(IO(SchemaRegistryContainer.Def(network, kafkaConfig.networkAlias).start()))(c => IO(c.stop()))
      .map { schemaRegistryContainer =>
        SchemaRegistryConfig(schemaRegistryContainer.schemaUrl)
      }

  def kafkaWithSchemaRegistry: Resource[IO, (KafkaConfig, SchemaRegistryConfig)] =
    for
      network <- Resource.fromAutoCloseable(IO(Network.newNetwork()))
      kafkaConfig <- kafka(network)
      schemaRegistryConfig <- schemaRegistry(network, kafkaConfig)
    yield (kafkaConfig, schemaRegistryConfig)

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.

1 participant