Giter Site home page Giter Site logo

aiven_services_example's Introduction

aiven_services_example

Aiven Kafka Quickstart with Flink and Python

1. Install Dependencies

pip install -r requirements.txt

2. Create Aiven Kafka service in UI or CLI

UI
CLI
  1. Create Aiven Account (Use SSO)

  2. Create Token for CLI Access in https://console.aiven.io/profile/tokens How To Create Authentication Tokens Save Token

  3. avn user login [email protected] --token #input token from step 2

  4. Set environment variables

KAFKA_INSTANCE_NAME=demokafka
CLOUD_PROVIDER=google-us-central1
AIVEN_PLAN_NAME=startup-2
DESTINATION_FOLDER_NAME=~/kafkacerts
  1. Use CLI to create Kafka cluster or UI by following Kafka getting started guide
avn service create  \
  -t kafka $KAFKA_INSTANCE_NAME \
  --cloud  $CLOUD_PROVIDER \
  -p $AIVEN_PLAN_NAME \
  -c kafka_rest=true \
  1. Download credentials for Python script
avn service user-creds-download $KAFKA_INSTANCE_NAME \
  -d $DESTINATION_FOLDER_NAME \
  --username avnadmin
  1. return the URI
avn service get $KAFKA_INSTANCE_NAME \                
  --format '{service_uri}'
  1. Wait Until Service is running
avn service wait $KAFKA_INSTANCE_NAME

3. Create Topic for service in UI or CLI

4. Use Service Name and cert directory for the arguments and run

python iot_faker.py \                                           
  --cert-folder ~/kafkacerts/ \
  --host demokafka-username-x11x.aivencloud.com \
  --port 27721 \
  --topic-name iot

5. Create Demo Flink Environment with UI or CLI. If UI, follow Flink getting started guide

avn service create demoflink -t flink --plan business-4

6. Enable Flink Data Service Integration with Kafka

7. Flink - Create New Application in the Applications tab

8. Flink - Create New Source Table

CREATE TABLE iot (
    device VARCHAR,
    deviceParameter VARCHAR,
    deviceValue INT,
    dateTime TIMESTAMP
) WITH (
    'connector' = 'kafka',
    'properties.bootstrap.servers' = '',
    'scan.startup.mode' = 'earliest-offset',
    'topic' = 'iot',
    'value.format' = 'json',
    'key.format' = 'json',
    'key.fields' = 'device'
)

9. Create Sink Table

CREATE TABLE temperatures (
    device VARCHAR,
    deviceValue INT,
    timed TIMESTAMP,
    jitter DOUBLE
) WITH (
    'connector' = 'kafka',
    'properties.bootstrap.servers' = '',
    'scan.startup.mode' = 'earliest-offset',
    'topic' = 'temperatures',
    'value.format' = 'json',
    'key.format' = 'json',
    'key.fields' = 'device'
)

10. Create the SQL statement that transforms the data from the source stream.

INSERT INTO temperatures
SELECT device, deviceValue, dateTime, RAND() AS jitter
FROM iot
WHERE deviceParameter = 'Temperature'

11. Create Deployment of Flink Application

12. Use UI to verify data in the Kafka sink Topic

aiven_services_example's People

Contributors

alinuxfan avatar

Watchers

 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.