https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol
If available in Hex, the package can be installed as:
- Add
kafkex
to your list of dependencies inmix.exs
:
```elixir
def deps do
[{:kafkex, git: "https://github.com/mikeurbach/kafkex.git", tag: "0.1"}]
end
```
- Ensure
kafkex
is started before your application:
```elixir
def application do
[applications: [:kafkex]]
end
```
iex(1)> {:ok, producer} = Kafkex.Producer.start_link({[{'localhost', 9092}], "foo"})
{:ok, #PID<0.188.0>}
iex(2)> 0..3 |> Enum.map(&Integer.to_string/1) |> Flow.from_enumerable |> Flow.into_stages([producer])
nil
iex(3)> {:ok, consumer} = Kafkex.Consumer.start_link({[{'localhost', 9092}], "foo", "group"})
...
{:ok, #PID<0.149.0>}
iex(4)> Flow.from_stages([consumer]) |> Enum.take(3)
...
[%Kafkex.Protocol.Message{key: "key", offset: 155227127,
timestamp: 1513012816377, value: "value"},
%Kafkex.Protocol.Message{key: "key", offset: 155227128,
timestamp: 1513012816377, value: "value"},
%Kafkex.Protocol.Message{key: "key", offset: 155227129,
timestamp: 1513012816377, value: "value"}]
...