Skip to content

Same client_id to different brokers #49

@manuscrypt

Description

@manuscrypt

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions