Giter Site home page Giter Site logo

kafka-connect-email's Introduction

kafka-connect-email

##Summary

kafka-connect-email is simple Apache Kafka Sink Connector. It reads messages from Kafka topics and send emails with those messages. Messages have to be in proper schema.

##Configuration

To use connector you need first setup Apache Kafka Cluster. For Kafka following docker image can be used: wardziniak/kafka

###Quick guide for Kafka

Start zookeeper

docker run -d --name zookeeper -p 2181:2181 jplock/zookeeper:3.4.9

Start kafka brokers

docker run -d --name kafka1 -p 9092:9092 --env ZOOKEEPER_IP=192.168.1.13 --env KAFKA_BROKER_ID=0 --env KAFKA_PORT=9092 --env KAFKA_ADVERTISED_PORT=9092 --env KAFKA_ADVERTISED_HOST_NAME=192.168.1.13 wardziniak/kafka
docker run -d --name kafka2 -p 9093:9093 --env ZOOKEEPER_IP=192.168.1.13 --env KAFKA_BROKER_ID=1 --env KAFKA_PORT=9093 --env KAFKA_ADVERTISED_PORT=9093 --env KAFKA_ADVERTISED_HOST_NAME=192.168.1.13 wardziniak/kafka

You have to change ZOOKEEPER_IP and KAFKA_ADVERTISED_HOST_NAME to ip of you machine. More detail can be found: https://hub.docker.com/r/wardziniak/kafka

When Apache Kafka is ready topic for reading emails message havet to be created. To do that you need download Apache Kafka from https://kafka.apache.org/downloads and run command:

./bin/kafka-topics.sh --create --zookeeper localhost:2181 --partitions 5 --replication-factor 2 --topic connect-email

###Guide for kafka-email-connector

Create property files in $KAFKA_HOME/config

  • config/connect-main.properties
bootstrap.servers=localhost:9092
key.converter=org.apache.kafka.connect.storage.StringConverter
value.converter=com.wardziniak.kafka.connect.email.EmailConverter
key.converter.schemas.enable=false
value.converter.schemas.enable=false
internal.key.converter=org.apache.kafka.connect.json.JsonConverter
internal.value.converter=org.apache.kafka.connect.json.JsonConverter
internal.key.converter.schemas.enable=false
internal.value.converter.schemas.enable=false
offset.storage.file.filename=/tmp/connect.offsets
offset.flush.interval.ms=10000
  • config/connect-email-sink.properties
name=local-email-sink
connector.class=com.wardziniak.kafka.connect.email.EmailSinkConnector
tasks.max=1
topics=connect-email
wardziniak.email.connect.hostname=smtp.googlemail.com
wardziniak.email.connect.smtp.port=465
wardziniak.email.connect.from.address[email protected]
wardziniak.email.connect.username[email protected]
wardziniak.email.connect.passoword=emailpassword
  • Notice
    • bootstrap.servers - address with port of Kafka broker
    • topics - Kafka topic created. Messages will be sent to it
    • wardziniak.email.connect.* - Email account settings

###Start connector

  • First you need to build it

    sbt assembly
    
  • Add to CLASSPATH assemblied jar ($PROJECT/target/scala-2.11/kafka-connect-email-assembly-1.0.jar)

  • Start connector

  $KAFKA_HOME/bin/connect-standalone.sh config/connect-main.properties config/connect-email-sink.properties

###Send Email

To send email you need to send message to propriate Kafka topic (ex. connect-email). You can use Kafka tools

$KAFKA_HOME/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic connect-email

Paste sample message

{"title":"Sample title","body":"Email content","toRecipients":[{"name":"Ludwig","emailAddress":"[email protected]"}]}

Json Schema for messages

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "title": {
      "type": "string"
    },
    "body": {
      "type": "string"
    },
    "toRecipients": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "emailAddress": {
            "type": "string"
          }
        },
        "required": [
          "name",
          "emailAddress"
        ]
      }
    }
  },
  "required": [
    "title",
    "body",
    "toRecipients"
  ]
}

Sample message:

{
  "title": "Sample title",
  "body": "Mail body",
  "toRecipients": [
    {
      "name": "Ludwig",
      "emailAddress": "[email protected]"
    }
  ]
}

kafka-connect-email's People

Contributors

wardziniak avatar

Watchers

James Cloos avatar

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.