kafka_ex icon indicating copy to clipboard operation
kafka_ex copied to clipboard

Allow worker name to be separated from process name

Open BlueCollarChris opened this issue 4 years ago • 5 comments

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 avatar Oct 21 '20 21:10 BlueCollarChris

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

BlueCollarChris avatar Oct 21 '20 21:10 BlueCollarChris

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.

joshuawscott avatar Oct 22 '20 13:10 joshuawscott

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

dantswain avatar Oct 22 '20 14:10 dantswain

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 avatar Nov 16 '20 17:11 BlueCollarChris

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.

BlueCollarChris avatar Nov 16 '20 18:11 BlueCollarChris