Skip to content

Commit

Permalink
feat!: add async producer (#10)
Browse files Browse the repository at this point in the history
This rewrites all of the Kafee modules to support async producing to Kafka.

**Breaking changes**: This rewrites Kafka. Time to relearn everything!
  • Loading branch information
btkostner authored Oct 10, 2022
1 parent d7f4533 commit cab0aee
Show file tree
Hide file tree
Showing 35 changed files with 1,827 additions and 624 deletions.
15 changes: 15 additions & 0 deletions .doctor.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%Doctor.Config{
ignore_modules: [],
ignore_paths: [],
min_module_doc_coverage: 80,
min_module_spec_coverage: 50,
min_overall_doc_coverage: 80,
min_overall_spec_coverage: 80,
moduledoc_required: true,
exception_moduledoc_required: true,
raise: true,
reporter: Doctor.Reporters.Full,
struct_type_spec_required: true,
umbrella: false,
failed: false
}
38 changes: 35 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,38 @@ jobs:
- name: Credo
run: mix credo

Dialyzer:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Elixir
uses: stordco/actions-elixir/setup@v1
with:
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
hex-token: ${{ secrets.HEX_API_KEY }}

- name: Dialyzer
run: mix dialyzer

Doctor:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Elixir
uses: stordco/actions-elixir/setup@v1
with:
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
hex-token: ${{ secrets.HEX_API_KEY }}

- name: Doctor
run: mix doctor

Format:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -66,9 +98,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Start Services
run: docker-compose up -d && sleep 10

- name: Setup Elixir
uses: stordco/actions-elixir/setup@v1
with:
Expand All @@ -80,5 +109,8 @@ jobs:
- name: Compile
run: mix compile --warnings-as-errors

- name: Start Services
run: docker-compose up -d && sleep 10

- name: Test
run: mix test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ tags
[._]*.un~

# End of https://www.toptal.com/developers/gitignore/api/elixir,phoenix,vim,macosx

.vscode
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.13
erlang 25
elixir 1.14
erlang 25.0
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,54 @@ end
```
<!-- {x-release-please-end} -->

## Documentation
## Published Documentation

Documentation is automatically generated and published to [HexDocs](https://stord.hexdocs.pm/kafee/readme.html) on new releases.

## Quick Start

### Producers

So you want to send messages to Kafka eh? Well, here is some code for you.

```elixir
defmodule MyProducer do
use Kafee.Producer,
producer_backend: Kafee.Producer.AsyncBackend,
topic: "my-kafka-topic"

def publish(:order_created, %Order{} = order) do
produce([%Kafee.Producer.Message{
key: order.tenant_id,
value: Jason.encode!(order)
}])
end
end

defmodule MyApplication do
use Application

def start(_type, _args) do
children = [
{MyProducer, [
host: "localhost",
port: 9092,
username: "username",
password: "password",
ssl: true,
sasl: :plain
]}
]

Supervisor.start_link(children, strategy: :one_for_one)
end
end
```

Once that is done, to publish a message simply run:

```elixir
MyProducer.publish(:order_created, %Order{})
```

See the `Kafee.Producer` module for more options and information.
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ services:
environment:
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_BROKER_ID: 1
KAFKA_CREATE_TOPICS: sync-producer-backend-test:4:1
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
KAFKA_LISTENERS: PLAINTEXT://:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_DELETE_TOPIC_ENABLED: 1
13 changes: 0 additions & 13 deletions lib/kafee.ex

This file was deleted.

13 changes: 9 additions & 4 deletions lib/kafee/application.ex
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
defmodule Kafee.Application do
@moduledoc false
@moduledoc """
Starts up application global processes, like the `Kafee.Producer.AsyncRegistry`.
"""

use Application

@doc false
@spec start(Application.start_type(), term()) :: {:ok, pid} | {:error, term()}
def start(_type, _args) do
children = []
children = [
{Registry, keys: :unique, name: Kafee.Producer.AsyncRegistry}
]

opts = [strategy: :one_for_one, name: Kafee.Supervisor]
Supervisor.start_link(children, opts)
Supervisor.start_link(children, strategy: :one_for_one)
end
end
28 changes: 0 additions & 28 deletions lib/kafee/message.ex

This file was deleted.

17 changes: 0 additions & 17 deletions lib/kafee/partitioner.ex

This file was deleted.

11 changes: 0 additions & 11 deletions lib/kafee/partitioners/random.ex

This file was deleted.

Loading

0 comments on commit cab0aee

Please sign in to comment.