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

Added examples for topic create/delete functions. #470

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions lib/kafka_ex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,39 @@ defmodule KafkaEx do
@doc """
Create topics. Must provide a list of CreateTopicsRequest, each containing
all the information needed for the creation of a new topic.

See available topic configuration options at https://docs.confluent.io/platform/current/installation/configuration/topic-configs.html

## Example

```elixir
iex> KafkaEx.start_link_worker(:my_kafka_worker)
{:ok, #PID<0.659.0>}
iex> KafkaEx.create_topics(
...> [
...> %KafkaEx.Protocol.CreateTopics.TopicRequest{
...> topic: "my_topic_name",
...> num_partitions: 1,
...> replication_factor: 1,
...> replica_assignment: [],
...> config_entries: [
...> %{config_name: "cleanup.policy", config_value: "delete"},
...> %{config_name: "delete.retention.ms", config_value: "864000000"} # 1 day
...> ]
...> }
...> ],
...> timeout: 10_000,
...> worker_name: :my_kafka_worker
...> )
%KafkaEx.Protocol.CreateTopics.Response{
topic_errors: [
%KafkaEx.Protocol.CreateTopics.TopicError{
error_code: :no_error,
topic_name: "my_topic_name"
}
]
}
```
"""
@spec create_topics([CreateTopicsRequest.t()], Keyword.t()) ::
CreateTopicsResponse.t()
Expand All @@ -722,6 +755,20 @@ defmodule KafkaEx do

@doc """
Delete topics. Must provide a list of topic names.

## Example

```elixir
iex> KafkaEx.delete_topics(["my_topic_name"], [])
%KafkaEx.Protocol.DeleteTopics.Response{
topic_errors: [
%KafkaEx.Protocol.DeleteTopics.TopicError{
error_code: :no_error,
topic_name: "my_topic_name"
}
]
}
```
"""
@spec delete_topics([String.t()], Keyword.t()) :: DeleteTopicsResponse.t()
def delete_topics(topics, opts \\ []) do
Expand Down