HareMq.DynamicSupervisor (hare_mq v1.4.0)

Copy Markdown

Per-module dynamic supervisor for HareMq.DynamicConsumer worker pools.

Each module that use HareMq.DynamicConsumer gets its own supervisor registered as :<ModuleName>.Supervisor (e.g. MyApp.Consumer.Supervisor). This allows multiple consumer modules to coexist on the same node without name conflicts.

Worker processes are started asynchronously (unlinked Task) so a startup failure (e.g. transient connection error) does not crash the supervisor.

Summary

Functions

Adds a new consumer worker to the running pool.

Returns a specification to start this module under a supervisor.

Initializes the dynamic supervisor.

Returns all child specs currently managed by supervisor.

Gracefully removes a running consumer by global name.

Starts the AutoScaler as a child under this DynamicSupervisor.

Starts a child worker under supervisor.

Returns the registered atom name for the supervisor managing module_name.

Functions

add_consumer(supervisor, list)

Adds a new consumer worker to the running pool.

Delegates to start_child/2. Useful when the auto-scaler scales up.

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

init(opts)

Initializes the dynamic supervisor.

Spawns an unlinked Task to start consumers and (if configured) the auto-scaler. Using an unlinked task means transient errors during consumer startup (e.g. waiting for a connection) do not crash the supervisor.

list_consumers(supervisor)

Returns all child specs currently managed by supervisor.

remove_consumer(supervisor, name)

Gracefully removes a running consumer by global name.

Sends :cancel_consume to allow the consumer to finish its current message, then terminates the process under the given supervisor. Returns :ok immediately if the named process is not found.

start_auto_scaler(opts)

Starts the AutoScaler as a child under this DynamicSupervisor.

start_child(supervisor, list)

Starts a child worker under supervisor.

  • supervisor — the name returned by supervisor_name/1.
  • worker: — the worker module (must implement start_link/1).
  • name: — global registration name string for the worker.
  • opts: — options forwarded to the worker's start_link.

start_link(opts)

supervisor_name(module_name)

Returns the registered atom name for the supervisor managing module_name.

Example

HareMq.DynamicSupervisor.supervisor_name(MyApp.Consumer)
# => :"MyApp.Consumer.Supervisor"