# `Pulsar.PartitionedProducer`
[🔗](https://github.com/efcasado/pulsar-elixir/blob/main/lib/pulsar/partitioned_producer.ex#L1)

A supervisor that manages individual producer groups for partitioned topics.

This module provides a logical abstraction over multiple producer groups,
allowing the `start_producer` API to return a single PID for partitioned topics
while maintaining the individual producer group architecture underneath.

The supervisor manages one producer group per partition, with the number of
partitions provided by the caller.

## Message Routing

Messages are routed to partitions based on the `:partition_key` option:
- With `:partition_key` - Consistent hash routing via `:erlang.phash2(partition_key, num_partitions)`
- Without `:partition_key` - Random selection

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `get_partition_groups`

Gets information about all child producer groups managed by this supervisor.

Returns a list of `{partition_topic, group_pid}` tuples.

# `get_producers`

Gets all producer processes from all partition groups managed by this supervisor.

Returns a flat list of producer process PIDs from all partitions.

# `send_message`

```elixir
@spec send_message(pid(), binary(), keyword()) :: {:ok, map()} | {:error, term()}
```

Sends a message through the partitioned producer.

Routes the message to a partition based on the `:partition_key` option:
- With `:partition_key` - Uses consistent hashing to route to a specific partition
- Without `:partition_key` - Uses random partition selection

## Parameters

- `supervisor_pid` - The partitioned producer supervisor PID
- `message` - Binary message payload
- `opts` - Optional parameters (same as `Pulsar.ProducerGroup.send_message/3`)

## Returns

`{:ok, message_id}` on success
`{:error, reason}` on failure

# `start_link`

Starts a partitioned producer supervisor.

## Parameters

- `name` - Unique name for this partitioned producer
- `topic` - The base partitioned topic name (without partition suffix)
- `partitions` - Number of partitions for this topic
- `opts` - Additional options passed to individual producer groups

## Returns

`{:ok, pid}` - The supervisor PID that manages all partition producer groups
`{:error, reason}` - Error if the supervisor failed to start

# `stop`

Stops a partitioned producer supervisor and all its child producer groups.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
