1stSolo
Kafka client GenServer restarting
I have a usecase where kafka endpoind information is entered by user. The endpoint is bound into Brod Client I’m starting and if that succeeds I start a Producer from that Client. If something fails, the GenServer is configured to do restart: :permanent. Which is a good thing because you want your client to try to restart if connection is severed or GenServer crashes for any reason. BUT since user entries are not fool-proof, a bad input such as non-existent Kafka broker will put GenServer into permanent restart loop.
How to best handle the situation where I want to avoid creating a client when user enters invalid Kafka configuration, but keep permanent restart mode if the configuration is valid?
Brod is doing it! brod/src/brod_sup.erl at 3.7.9 · kafka4beam/brod · GitHub
Maybe the best protection is to have separate code that validates the endpoint user entry and makes sure it’s live before attempting to start a client instance?..
Marked As Solved
1stSolo
Unable. permanent is hardcoded in Brod library. Only thing you can change is delay between restarts.
My solution was to again use Brod to ping the brokers via get_metadata() and create client and producer only if response was {:ok, _metadata}. Otherwise I don’t create brokers and return :error.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








