Giter Club home page Giter Club logo

kashka's Introduction

Kashka

Elixir Kafka REST proxy client for Confluent REST Proxy.

Examples

Produce

{:ok, conn} = Kashka.Kafka.produce("http://localhost:8082/", "topic_name', [%{value: %{foo: "bar"}}])
:ok == Kashka.Kafka.close(conn)

See Kashka.Kafka.produce/4 for details.

Consume

defmodule TestModule do
  @behaviour Kashka.GenConsumer

  def init(conn, _args) do
    {:ok, conn, :state}
  end

  def handle_message_set(conn, :state, message_set) do
    IO.inspect(message_set)

    #[%{"key" => nil, "offset" => 0, "partition" => 0, "topic" => "test_name", "value" => %{"foo" => "bar"}}]

    {:ok, conn, :state}
  end
end

args = [
  url: "http://localhost:8082/",
  instance_id: "my",
  consumer_group: "consumer_group",
  topics: ["topic_name"],
  module: TestModule,
  delete_on_exists: false,
  retry_on_exists: true,
  consumer_opts: %{"auto.offset.reset": :earliest, "auto.commit.enable": true},
]

{:ok, pid} = GenConsumer.start_link(args)

See Kashka.GenConsumer for details.

More

See tests for more examples.

Kafka URL explanation

Kafka URL can be a String or a Keyword list. Keyword list can contain url, headers, fix_schema, fix_port, fix_host keys.

Examples:

[url: "http://127.0.0.1:8811", headers: [{"host", "smth.com"}]]

With fix_* keys:

[url: "http://127.0.0.1", fix_port: true, fix_schema: true, fix_host: true, headers: [{"host", "smth.com"}]]

fix_* keys used to automatically preprocess the URL returned from the consumer creation method.

For example if create_consumer method returns https://smth1.com:443/comsumers/group/instances/name as a base_uri, it is transformed to http://127.0.0.1:80/comsumers/group/instances/name with host header smth1.com.

It can be helpful while connecting to Kafka REST API through Nginx proxy.

protocols: option can be used for explicit specification of HTTP protocols negotiation with Kafka REST server. It can take the following values: :http1, :http2 or :any by default.

How to run tests

  1. Run doker-compose up.
  2. Run mix test in separate terminal.

Roadmap

  • Make protection from endless loop in Kashka.Http.request.
  • Correctly process other errors in Kashka.Http.request.

Sponsored by FunBox

kashka's People

Contributors

savonarola avatar netdalek avatar igoradamenko avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

kashka's Issues

Passing invalid params to Mint

The module Kashka.Http passes invalid params to Mint.HTTP.connect/4 in the line 148.
@https_connect_opts has structure [transport_opts: [verify: :verify_none]], so we have the warning

iex(10)> Mint.HTTP.connect(:https, "https://www.yandex.ru", 443, [transport_opts: [verify: :verify_none]])

14:58:33.434 [warn]  Description: 'Authenticity is not established by certificate path validation'
     Reason: 'Option {verify, verify_peer} and cacertfile/cacerts is missing'

Update Mint

Kashka has errors with new version of Elixir, the cause in old version of Mint

Interactive Elixir (1.12.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Mint.HTTP.connect(:https, "https://www.yandex.ru", 443, [transport_opts: [verify: :verify_none]])
** (UndefinedFunctionError) function :ssl.cipher_suites/0 is undefined or private, use cipher_suites/2,3 instead
    (ssl 10.5) :ssl.cipher_suites()
    (mint 0.4.0) lib/mint/core/transport/ssl.ex:558: Mint.Core.Transport.SSL.default_ciphers/0
    (mint 0.4.0) lib/mint/core/transport/ssl.ex:474: Mint.Core.Transport.SSL.default_ssl_opts/1
    (mint 0.4.0) lib/mint/core/transport/ssl.ex:405: Mint.Core.Transport.SSL.ssl_opts/2
    (mint 0.4.0) lib/mint/core/transport/ssl.ex:318: Mint.Core.Transport.SSL.connect/3
    (mint 0.4.0) lib/mint/negotiate.ex:65: Mint.Negotiate.connect_negotiate/4

ssl:cipher_suites/0 deprecated in OTP 21

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.