kafkaex / kafka_ex

Kafka client library for Elixir
MIT License
596 stars 162 forks source link

Allow worker name to be separated from process name #416

Open BlueCollarChris opened 3 years ago

BlueCollarChris commented 3 years ago

https://github.com/kafkaex/kafka_ex/blob/a1bd36052f4b212fda62795279775ebbc498c407/lib/kafka_ex/new/client.ex#L40

Requested

# additional function argument that can contain [name: my_desired_name]
def start_link(args, name, opts) do
    GenServer.start_link(__MODULE__, [args, name], opts)
end

OR

# where args contains the desired worker name
def start_link(args, opts) do
    GenServer.start_link(__MODULE__, [args], opts)
end
BlueCollarChris commented 3 years ago

If this is something that can be added I would perform the work and open a PR just not sure what you guys are thinking

joshuawscott commented 3 years ago

This seems like a good idea to me. I think perhaps we could go with the second version where we can extract the name from opts, since normally a GenServer uses a name passed in the final options keyword list.

dantswain commented 3 years ago

The name argument was for compatibility with the existing supervisor. I'd have to dig a little to remember why but the tests should fail if anything gets broken too badly.

I think something like this would make sense

def start_link(args, gen_server_opts \\ []) do
  final_args = case Keyword.fetch(gen_server_opts, :name) do
    {:ok, name} -> args ++ [name: name]
    :error -> args
  end
  GenServer.start_link(__MODULE__, [final_args], gen_server_opts)
end
BlueCollarChris commented 3 years ago

Sorry I got sidetracked and forgot to keep up with the thread, but I will take what @dantswain mentioned and go ahead and incorporate that then open PR.

BlueCollarChris commented 3 years ago

Actually doing it that way would then tie the worker name back to the genserver when its not very elegant to have a worker named in a way the genserver may be named. I think they need to be separated completely as the name of the worker and genserver should never cross paths.