Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
1 result

python

  • Clone with SSH
  • Clone with HTTPS
  • user avatar
    Seok Won authored
    pip install faust
    8ef04d59
    History
    Name Last commit Last update
    ..
    src
    tests
    README.md

    Apache Kafka 공부 in Python

    v2.13-2.6.0

    Apache Kafka

    설치

    Kafka 다운로드

    Make sure to Download "Binary"

    실행

    zookeeper & kafka 서버 실행

    
    WIN10@DESKTOP:~$ zookeeper-server-start config/zookeeper.properties
    
    WIN10@DESKTOP:~$ kafka-server-start config/server.properties
    

    Kafka 설치

    
    WIN10@DESKTOP:~$ pip install confluent-kafka
    

    Slack API with Ajou University notices parser

    Get Slack API here

    First, invite your bot to your channel. (In this example, we set it as "#아주대")

    The producer will notify the consumer whenever there are new notices.

    The producer checks new notices per an hour, saves latest 10 notices to json file, and sees if there is/are a new notice/s.

    If there is a new notice, it sends {"TITLE": "title", "DATE": "post date", "LINK": "http address", "WRITER": "writer"} to the consumer.

    The consumer checks new datas every 5 seconds, if it gets a new data, it consumes the data and leave a comment like this below image.

    🅱️ Run the server first to see the results.

    WIN10@DESKTOP:~$ python AjouSlackProducer.py
    
    WIN10@DESKTOP:~$ python AjouSlackConsumer.py

    Slack API Producer Usage

    Get Slack API

    Invite your bot to user community channel and your developer channel.

    This producer sends a data if users post comments containing a word, "bug".

    example data)
    { "USER": "ikr", "TEXT": "I found a bug! I can keep copying my items to my inventory." }

    Then the consumer below, will consume the data and posts a message in your developer channel.

    "USERNAME: MESSAGE: Please see if we can fix it right here, right now"

    Slack API Consumer Usage

    Modified version of official Confluent example

    Get Slack API

    Add "chat:write" scope to both user and bot.

    Copy Bot User OAuth Access Token from OAuth & Permissions section.

    /INVITE @BOTNAME

    to your channel if you see an error, "** FAILED: not_in_channel"

    Using CLI or producers, send a data to your kafka topic.

    kafka-console-producer --broker-list localhost:9092 --topic SLACK-KAFKA
    > {"CLUB_STATUS":"platinum","EMAIL":"ikr@kakao.com","STARS":1,"MESSAGE":"Exceeded all my expectations!"}

    Whenever you send a data to kafka, this consumer consumes email and message from the user, and posts "EMAIL just left a bad review" to your slack channel.

    Result
    
    Sending message "`ikr@kakao.com` just left a bad review :disappointed:
    > Exceeded all my expectations!
    
    _Please contact them immediately and see if we can fix the issue *right here, right now*_" to channel kafka