Coder Social home page Coder Social logo

kafka-to-google-hangouts's Introduction

Streaming messages from Apache Kafka to Google Hangouts bot

This project enables messages streaming process from Apache Kafka to Google Hangouts bot.

Prerequisite

You need to have a running Kafka service.

Environment configurations and validations

Open config.cfg and edit the values using text editor:

$ vim config.cfg

or

$ nano config.cfg

Now let's check if Producer and Consumer are able to send and receive messages.

$ python kafka-test.py
...
ConsumerRecord(topic=u'mytopic', partition=1, offset=2244, timestamp=1532095366718, timestamp_type=0, key=None, value='test', checksum=None, serialized_key_size=-1, serialized_value_size=4)
ConsumerRecord(topic=u'mytopic', partition=1, offset=2245, timestamp=1532095366718, timestamp_type=0, key=None, value='\xc2Hola, mundo!', checksum=None, serialized_key_size=-1, serialized_value_size=13)
...

If you can see the above ConsumerRecords, then let's validate if Google Hangouts bot's webhook is running.

$ python hangouts-test.py
({'status': '200', 'content-length': '585', 'x-xss-protection': '1; mode=block', 'x-content-type-options': 'nosniff', 'transfer-encoding': 'chunked', 'vary': 'Origin, X-Origin, Referer', 'server': 'ESF', '-content-encoding': 'gzip', 'cache-control': 'private', 'date': 'Mon, 23 Jul 2018 06:27:01 GMT', 'x-frame-options': 'SAMEORIGIN', 'alt-svc': 'quic=":443"; ma=2592000; v="44,43,39,35"', 'content-type': 'application/json; charset=UTF-8'}, '{\n  "name": "spaces/AAAAXcBQUfE/messages/B-Jo5s-SKMA.B-Jo5s-SKMA",\n  "sender": {\n    "name": "users/114022495153014004089",\n    "displayName": "gcp-awesome-bot",\n    "avatarUrl": "",\n    "email": "",\n    "type": "BOT"\n  },\n  "text": "Hello worlds!",\n  "cards": [],\n  "previewText": "",\n  "annotations": [],\n  "thread": {\n    "name": "spaces/AAAAXcBQUfE/threads/B-Jo5s-SKMA"\n  },\n  "space": {\n    "name": "spaces/AAAAXcBQUfE",\n    "type": "ROOM",\n    "displayName": "GCP-POC"\n  },\n  "fallbackText": "",\n  "argumentText": "Hello worlds!",\n  "createTime": "2018-07-23T06:27:01.584735Z"\n}\n')
...

Step-by-step

Now let's stream the messages from Kafka to Google Hangout bot.

$ python kafka-to-google-hangouts.py
...
({'status': '200', 'content-length': '681', 'x-xss-protection': '1; mode=block', 'x-content-type-options': 'nosniff', 'transfer-encoding': 'chunked', 'vary': 'Origin, X-Origin, Referer', 'server': 'ESF', '-content-encoding': 'gzip', 'cache-control': 'private', 'date': 'Mon, 23 Jul 2018 06:21:43 GMT', 'x-frame-options': 'SAMEORIGIN', 'alt-svc': 'quic=":443"; ma=2592000; v="44,43,39,35"', 'content-type': 'application/json; charset=UTF-8'}, '{\n  "name": "spaces/AAAAXcBQUfE/messages/sVjuLVzBTt4.sVjuLVzBTt4",\n  "sender": {\n    "name": "users/114022495153014004089",\n    "displayName": "gcp-awesome-bot",\n    "avatarUrl": "",\n    "email": "",\n    "type": "BOT"\n  },\n  "text": "@stories_startup Finally its for free https://t.co/ysIsYF4I3R",\n  "cards": [],\n  "previewText": "",\n  "annotations": [],\n  "thread": {\n    "name": "spaces/AAAAXcBQUfE/threads/sVjuLVzBTt4"\n  },\n  "space": {\n    "name": "spaces/AAAAXcBQUfE",\n    "type": "ROOM",\n    "displayName": "GCP-POC"\n  },\n  "fallbackText": "",\n  "argumentText": "@stories_startup Finally its for free https://t.co/ysIsYF4I3R",\n  "createTime": "2018-07-23T06:21:43.770383Z"\n}\n')
...

Congrats! Now the Kafka can stream the realtime message from Apache Kafka to Google Hangout bot.

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.