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

Same client_id to different brokers #49

Open
manuscrypt opened this issue Aug 13, 2023 · 1 comment
Open

Same client_id to different brokers #49

manuscrypt opened this issue Aug 13, 2023 · 1 comment

Comments

@manuscrypt
Copy link

manuscrypt commented Aug 13, 2023

I am trying to create multiple connections to different mqtt-brokers, but it seems that the client_id is used to register the processes.

Is there a way to achieve this with options I am not aware of, or would it require a change to the library?

Below is my code. When I concat env to the client_id, it does not crash with "already started", but then the server refuses to connect, since the client_id/username/password-combination is incorrect.

pids =
  ["dev", "stage", "prod"]
  |> Enum.map(fn env ->
    server_opts = Application.fetch_env!(:my_app, String.to_atom(env))

    {:ok, pid} =
      Tortoise311.Supervisor.start_child(
        MyApp.Connection.Supervisor,
        name: {:global, env},
        client_id: "my_client_id",
        user_name: "my_client_id",
        password: "my_client_id",
        server: server_opts,
        handler: {Tortoise311.Handler.Logger, [env]},
        subscriptions: [{"my/topics/#", 0}]
      )

    IO.inspect(pid)
    pid
  end)
@manuscrypt
Copy link
Author

I created #50, which seems to solve my problem, but I am really new to elixir and not very convinced this is all there is to it.

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

No branches or pull requests

1 participant