[sr-dev] [kamailio/kamailio] kafka: module to produce and send messages to a Kafka server (#2112)

vhernando notifications at github.com
Wed Oct 30 20:32:06 CET 2019


<!-- Kamailio Pull Request Template -->

<!--
IMPORTANT:
  - for detailed contributing guidelines, read:
    https://github.com/kamailio/kamailio/blob/master/.github/CONTRIBUTING.md
  - pull requests must be done to master branch, unless they are backports
    of fixes from master branch to a stable branch
  - backports to stable branches must be done with 'git cherry-pick -x ...'
  - code is contributed under BSD for core and main components (tm, sl, auth, tls)
  - code is contributed GPLv2 or a compatible license for the other components
  - GPL code is contributed with OpenSSL licensing exception
-->

#### Pre-Submission Checklist
<!-- Go over all points below, and after creating the PR, tick all the checkboxes that apply -->
<!-- All points should be verified, otherwise, read the CONTRIBUTING guidelines from above-->
<!-- If you're unsure about any of these, don't hesitate to ask on sr-dev mailing list -->
- [x] Commit message has the format required by CONTRIBUTING guide
- [x] Commits are split per component (core, individual modules, libs, utils, ...)
- [x] Each component has a single commit (if not, squash them into one commit)
- [x] No commits to README files for modules (changes must be done to docbook files
in `doc/` subfolder, the README file is autogenerated)

#### Type Of Change
- [ ] Small bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds new functionality)
- [ ] Breaking change (fix or feature that would change existing functionality)

#### Checklist:
<!-- Go over all points below, and after creating the PR, tick the checkboxes that apply -->
- [ ] PR should be backported to stable branches
- [x] Tested changes locally
- [ ] Related to issue #XXXX (replace XXXX with an open issue number)

#### Description
<!-- Describe your changes in detail -->

Module to produce and send messages to a Kafka server busing librdkafka library.

I copy part of README file here:


Chapter 1. Admin Guide

   Table of Contents

   1. Overview
   2. Dependencies

        2.1. Kamailio Modules
        2.2. External Libraries or Applications
        2.3. Parameters

              2.3.1. brokers (string)
              2.3.2. configuration (string)
              2.3.3. topic (string)

        2.4. Functions

              2.4.1. kafka_send(topic, msg)

        2.5. RPC Commands

              2.5.1. kafka.stats
              2.5.2. kafka.stats_topic

1. Overview

   This module produces and sends messages to a Kafka server.

2. Dependencies

   2.1. Kamailio Modules
   2.2. External Libraries or Applications
   2.3. Parameters

        2.3.1. brokers (string)
        2.3.2. configuration (string)
        2.3.3. topic (string)

   2.4. Functions

        2.4.1. kafka_send(topic, msg)

   2.5. RPC Commands

        2.5.1. kafka.stats
        2.5.2. kafka.stats_topic

2.1. Kamailio Modules

   The following modules must be loaded before this module:
     * none.

2.2. External Libraries or Applications

   The following libraries or applications must be installed before
   running Kamailio with this module loaded:
     * librdkafka: the Apache Kafka C/C++ client library.
       https://github.com/edenhill/librdkafka

2.3. Parameters

2.3.1. brokers (string)

   Specifies a list of brokers separated by commas.

   From librdkafka documentation:

   brokerlist is a ,-separated list of brokers in the format:
   <broker1>,<broker2>,

   Where each broker is in either the host or URL based format:
     * <host>[:<port>]
     * <proto>://<host>[:port]

   <proto> is either PLAINTEXT, SSL, SASL, SASL_PLAINTEXT

   The two formats can be mixed but ultimately the value of the
   security.protocol config property decides what brokers are allowed.

   This parameter is mandatory. There is no default value.

   Example 1.1. Set brokers parameter
...
modparam("kafka", "brokers", "localhost:9092")
modparam("kafka", "brokers", "broker1:10000,broker2")
modparam("kafka", "brokers", "SSL://broker3:9000,ssl://broker2")
...

2.3.2. configuration (string)

   Specifies a set of general properties.

   Each configuration property follows: name = value pattern. And
   configuration properties are separated by ;

   This parameter is optional, but if it exists it can be configured only
   once.

   Example 1.2. Set configuration parameter
...
modparam("kafka", "configuration", "topic.metadata.refresh.interval.ms=20000;que
ue.buffering.max.messages=1000000;metadata.request.timeout.ms=90000")

modparam("kafka", "configuration", "topic.metadata.refresh.interval.ms=20000;que
ue.buffering.max.messages=500000;debug=all;metadata.request.timeout.ms=900000")
...

2.3.3. topic (string)

   Specifies a topic name and a set of topic properties.

   The topic defined in topic parameter has to already exist in Kafka
   servers.

   Each topic property is a list of attribute = value separated by
   semicolon.

   name atribute indicates the topic name. It is mandatory. Other
   attributes mean names of properties and are optional.

   This parameter is optional. Each topic needs a topic parameter so
   several topic parameters are allowed.

   Example 1.3. Set topic parameter
...
modparam("kafka", "topic", "name=my_topic;request.required.acks=0;request.timeou
t.ms=10000")
modparam("kafka", "topic", "name=second_topic;request.required.acks=0;request.ti
meout.ms=10000")
modparam("kafka", "topic", "name=third_topic")
...

2.4. Functions

2.4.1.  kafka_send(topic, msg)

   Send a message to a specific topic via Kafka server.

   Parameters:
     * topic: (string) name of the topic. It is mandatory.
     * msg: (string) message to send. It is mandatory.

   Available via KEMI framework as kafka.send.

   Example 1.4. kafka_send usage
...
# Send "test message" to topic "my_topic"
kafka_send("my_topic", "test message");
...

2.5. RPC Commands

2.5.1. kafka.stats

   Show statistics about total sent messages and failed to deliver ones.

   Example 1.5. kafka.stats usage
...
kamcmd kafka.stats
Total messages: 26  Errors: 0
...

2.5.2. kafka.stats_topic

   Show statistics about sent messages and failed to deliver ones for a
   specific topic.

   Parameter: topic (string) name of the topic. Required.

   Example 1.6. kafka.stats usage
...
# Show statistics for my_topic.
kamcmd kafka.stats_topic "my_topic"
Topic: my_topic  Total messages: 17  Errors: 0
...

You can view, comment on, or merge this pull request online at:

  https://github.com/kamailio/kamailio/pull/2112

-- Commit Summary --

  * kafka: module to produce and send messages to a Kafka server

-- File Changes --

    A src/modules/kafka/Makefile (23)
    A src/modules/kafka/doc/Makefile (4)
    A src/modules/kafka/doc/kafka.xml (41)
    A src/modules/kafka/doc/kafka_admin.xml (221)
    A src/modules/kafka/kafka_mod.c (335)
    A src/modules/kafka/kfk.c (1175)
    A src/modules/kafka/kfk.h (96)

-- Patch Links --

https://github.com/kamailio/kamailio/pull/2112.patch
https://github.com/kamailio/kamailio/pull/2112.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/2112
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20191030/9679cba0/attachment.html>


More information about the sr-dev mailing list