Code Monkey home page Code Monkey logo

kafkablockchain's Introduction

Connector Version Source Technology Version Confluent Platorm Version
1.0 Ai-BlockChain 1.0 Compatible Confluent Platform Version - โ‰ฅ5.0.X

KafkaBlockchain

KafkaBlockchain is a java library for tamper-evidence using Kafka. Messages are optionally encrypted and hashed sequentially. The library methods are called within a Kafka application's message producer code to wrap messages, and called within the application's consumer code to unwrap messages. A sample utility program is provided that consumes and verifies a blockchained topic.

Because blockchains must be strictly sequentially ordered, Kafka blockchain topics must either have a single partition, or consumers for each partition must cooperate to sequence the records. Sample programs demonstrate blockchains with a single partition and with multiple partitions. If multiple producers exist, they must cooperate to serially add records to a Kafka blockchain.

KafkaBlockchain Components

Kafka already implements checksums for message streams to detect data loss. However, an attacker can provide false records that have correct checksums. Cryptographic hashes such as the standard SHA-256 algorithm are very difficult to falsify, which makes them ideal for tamper-evidence despite being a bit more computation than checksums.

To manage Kafka blockchains, the sample programs store the first (genesis) message SHA-256 hash for each blockchain topic in ZooKeeper. In production, secret keeping facilities, for example Vault can be used.

Try KafkaBlockchain on AWS: On the Amazon cloud, there is a prepared Ubuntu image with Java 14, Maven, Apache Kafka and KafkaBlockchain installed and ready to demonstrate.

Using the AiB KafkaBlockchain Demo on AWS

How the KafkaBlockchain image is built: Here are the instructions for building the KafkaBlockchain demonstration image on AWS. The steps are similar for a build elsewhere. Building the AiB KafkaBlockchain AMI on Amazon Web Services

Dependencies: This library uses the Bouncy Castle crypto library. Apache Maven is required to build this library, and to run the quickstart examples. This library is written using Java 10. The jar file is shaded such that the dependencies are hidden from any Maven project which includes KafkaBlockchain as a dependency.

Goodies: Included are utility classes: ByteUtils, KafkaAccess, ZooKeeperAccess, SHA256Hash and Serialization.

Quickstart

Java 14, using the preview feature for immutable records.

The Confluent webinar documentation is in the TERecord branch only.

Compile and test the library

git clone https://github.com/ai-coin/KafkaBlockchain.git git checkout TERecord java -version # ensure java version 14 export _JAVA_OPTIONS='-ea -Xms1G -Xmx5G --enable-preview' cd KafkaBlockchain; mvn test

Java 10+.

Compile and test the library

git clone https://github.com/ai-coin/KafkaBlockchain.git cd KafkaBlockchain; mvn test

These demonstrations perform KafkaBlockchain operations using a test Kafka broker configured per Kafka Quickstart".

Launch ZooKeeper in a terminal session

cd ~/kafka_2.12-2.5.0; bin/zookeeper-server-start.sh config/zookeeper.properties

Launch Kafka in a second terminal session after ZooKeeper initializes.

cd ~/kafka_2.12-2.5.0; bin/kafka-server-start.sh config/server.properties

Launch the demonstrations in a third terminal session after Kafka initializes.

Kafka blockchain demonstration

Navigate to this project's directory, and launch this script in a third terminal session which runs the KafkaBlockchain demo.

scripts/run-kafka-blockchain-demo.sh

The first program produces four payloads on the blockchain and then consumes them. A second program verifies the whole blockchain. Before re-running this demonstration, remove the previous blockchain messages by running this script first.

scripts/run-kafka-blockchain-demo-reset.sh

Kafka blockchain multiple partition demonstration

Navigate to this project's directory, and launch this script in a third terminal session which runs the KafkaBlockchain demo.

scripts/run-kafka-blockchain-multiple-partition-demo.sh

The first program produces four payloads on the blockchain and then consumes them. A second program verifies the whole blockchain. Before re-running this demonstration, remove the previous blockchain messages by running this script first.

scripts/run-kafka-blockchain-multiple-partition-demo-reset.sh

Kafka encrypted blockchain demonstration

Navigate to this project's directory, and launch this script in the third terminal session which runs the KafkaBlockchain encryption demo.

scripts/run-kafka-blockchain-encryption-demo.sh

The program produces four encrypted payloads on the blockchain and then consumes them with decryption. A second program verifies the whole blockchain without needing to decrypt it. Before re-running this demonstration, remove the previous blockchain messages by running this script first.

scripts/run-kafka-blockchain-demo-encryption-reset.sh

Kafka blockchain benchmark

Navigate to this project's directory, and launch this script in the third terminal session which runs the KafkaBlockchain benchmark. The producer creates 10 million messages for the Kafka blockchain with three partitions. A second program reads the 10 million messages and verifies the correctness of the blockchain. The demonstration payload is efficiently serialized using tailored methods that implement Externalizable. The benchmark takes a couple of minutes to create the messages and about five minutes more to verify the integrity of the 10 million messages with a consumer thread for each partition.

scripts/run-kafka-blockchain-benchmark.sh

Before re-running this benchmark, remove the previous 10 million blockchain messages by running this script first.

scripts/run-kafka-blockchain-benchmark-reset.sh

shutdown

After the demo is complete, shut down the Kafka session with Ctrl-C.

Shut down the ZooKeeper session with Ctrl-C.

kafkablockchain's People

Contributors

stephenlreed 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.