Skip to content

use standard port 9092 in KafkaContainer#733

Merged
bsideup merged 2 commits into
masterfrom
kafka_ux
Jun 11, 2018
Merged

use standard port 9092 in KafkaContainer#733
bsideup merged 2 commits into
masterfrom
kafka_ux

Conversation

@bsideup
Copy link
Copy Markdown
Member

@bsideup bsideup commented Jun 5, 2018

See #732

@bsideup bsideup added this to the next milestone Jun 5, 2018
@bsideup bsideup requested review from kiview and rnorth June 5, 2018 11:45
@iNikem
Copy link
Copy Markdown
Contributor

iNikem commented Jun 5, 2018

@bsideup When can we expect a public release for this? :)

Copy link
Copy Markdown
Member

@kiview kiview left a comment

Choose a reason for hiding this comment

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

Looks like an elegant solution to me.

proxy = new SocatContainer()
.withNetwork(getNetwork())
.withTarget(9092, networkAlias)
.withTarget(9093, networkAlias)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it would be more consistent to use KAFKA_PORT here (as well as in line 35).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@kiview changed to constants, could you please re-check?

@bsideup
Copy link
Copy Markdown
Member Author

bsideup commented Jun 5, 2018

@iNikem we prepare some exciting changes (e.g. #710 ) for a next release, but if it will take more than it should, we will cut another minor release soon-ish to release what's done already

Copy link
Copy Markdown
Member

@kiview kiview left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@bsideup bsideup merged commit acf904d into master Jun 11, 2018
@bsideup bsideup deleted the kafka_ux branch June 11, 2018 08:30
@iNikem
Copy link
Copy Markdown
Contributor

iNikem commented Aug 7, 2018

Now, coming back to this after 2 months, I discovered that I don't understand how I should use KafkaContainer now :)

  1. How do I connect to it from my test?
  2. How do I connect to it from another test container?

@bsideup Can you help me? Then I probably will can make a PR to your official documentation :)

@bsideup
Copy link
Copy Markdown
Member Author

bsideup commented Aug 7, 2018

@iNikem that would be amazing!

  1. use kafka.getBootstrapServers()
  2. put them into the same network (or use Kafka's network) and use port 9092. Example: https://github.com/bsideup/liiklus/blob/5faecebde8728865dff2bd7968b306b4fbedad1b/examples/plugin/src/test/java/com/github/bsideup/liiklus/plugins/example/support/AbstractIntegrationTest.java#L31

@YNedderhoff
Copy link
Copy Markdown

YNedderhoff commented Sep 5, 2019

@bsideup @iNikem has this been documented in the meantime? I am trying the exact use case right now. I have all containers including the application that uses Kafka in one Network. Then I have tests outside the network. The producer in the tests connects fine using getBootstrapServers(). If I use kafka:9093 in the application, it says that it can not connect to the broker localhost:<mappedPort>, which makes sense I think? But when I use kafka:9092, the app complains about this instead:

2019-09-05 15:40:08,903 WARN  [   o.a.k.clients.NetworkClient] [] - [Consumer clientId=consumer-1, groupId=myGroupId] Error while fetching metadata with correlation id 2 : {myTopic=LEADER_NOT_AVAILABLE}

A quick google indicates it might have something to do with advertised hosts?

@iNikem
Copy link
Copy Markdown
Contributor

iNikem commented Sep 5, 2019

@YNedderhoff With recent versions of testcontainers the following setup works nicely for me:

  1. Create a network for all your containers: private Network network = Network.newNetwork()
  2. Put all containers on this network and give them aliases:
    private KafkaContainer kafka = new KafkaContainer().withNetwork(network).withNetworkAliases('kafka')

Then all containers can access Kafka on kafka:9092. Your test, which runs outside the container, can access kafka on kafka.getBootstrapServers()

@YNedderhoff
Copy link
Copy Markdown

That's precisely my setup. Maybe it is actually working, I just know that my Spring app complains with that LEADER_NOT_AVAILABLE error I quoted above. I haven't actually fully tried to use Kafka in the tests yet, I am still in the setup phase.

@YNedderhoff
Copy link
Copy Markdown

Ok - I think you are right. Despite that message the app seems to consume data alright. Confusing, but nice that it works :) Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants