Kalium

A reactive framework for micro-services. current commit_id=v0.0.4.dirty

License

License

Categories

Categories

Kalium Security
GroupId

GroupId

io.alkal
ArtifactId

ArtifactId

kalium
Last Version

Last Version

0.0.4
Release Date

Release Date

Type

Type

jar
Description

Description

Kalium
A reactive framework for micro-services. current commit_id=v0.0.4.dirty
Project URL

Project URL

https://kalium.alkal.io
Source Code Management

Source Code Management

http://github.com/alkal-io/kalium.git

Download kalium

How to add to project

<!-- https://jarcasting.com/artifacts/io.alkal/kalium/ -->
<dependency>
    <groupId>io.alkal</groupId>
    <artifactId>kalium</artifactId>
    <version>0.0.4</version>
</dependency>
// https://jarcasting.com/artifacts/io.alkal/kalium/
implementation 'io.alkal:kalium:0.0.4'
// https://jarcasting.com/artifacts/io.alkal/kalium/
implementation ("io.alkal:kalium:0.0.4")
'io.alkal:kalium:jar:0.0.4'
<dependency org="io.alkal" name="kalium" rev="0.0.4">
  <artifact name="kalium" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.alkal', module='kalium', version='0.0.4')
)
libraryDependencies += "io.alkal" % "kalium" % "0.0.4"
[io.alkal/kalium "0.0.4"]

Dependencies

compile (1)

Group / Artifact Type Version
org.apache.commons : commons-math3 jar 3.6.1

runtime (1)

Group / Artifact Type Version
com.google.guava : guava jar 28.1-jre

Project Modules

There are no modules declared in this project.

Kalium: a reactive framework for micro-services

Build Status Maintainability Test Coverage codecov Total alerts Language grade: Java Known Vulnerabilities

Kalium in neo-latin is the word for Pottasium- the chemical element of atomic number 19, a soft silvery-white reactive metal of the alkali metal group.

What is Kalium?

Kalium is a framework that makes it easier for micro-services asynchronously to interact with each other.

Here's an example in Java. Let's assume we have an e-commerce site that accepts payments and sends receipts to customers. Upon checkout, a customer is sending a Payment. Once the Payment is processed, a Receipt needs to be sent to the customer.

For scale purposes, we assume payments are processed on one micro-service, while receipts are produced and sent from different micro-services.

Here is how we would use Kalium to help us with these data flows.

Processing a payment

 public class PaymentProcessor {
    ...
    @On
    public void processPayment(Payment payment) {
        if(!payment.isProcessed()) {
            // Do something with the payment, e.g. call Stripe to make the actual payment
            payment.processed = true;
            kalium.post(payment);
        }
    }
 }

Preparing a receipt

 public class ReceiptProducer {
    ...
    @On
    public void prepareReceipt(Payment payment) {
        if(payment.isProcessed()) {
            //convert processed payment into receipt
            Receipt newReceipt = converPaymentToReceipt(payment);
            kalium.post(newReceipt);
        }
    }
 }

Emailing a receipt to a customer

 public class ReceiptMailer {
    ...
    @On
    public void sendReceipt(Receipt receipt) {
        //send the receipt, e.g. convert it to HTML and send it with SendGrid
        prepareReceiptEmailAndSend(receipt);
        receipt.sent = true;
        kalium.post(receipt);
    }
 }

How Kalium works?

Behind the scenes, Kalium is using existing queue technology as a scalable event bus. Kalium uses the @On annotations to define out-of-the-box serializer/de-serializer for the event classes. The object type of the paramater of the annotated method, is used as the topic in the underlying queue.

Currently, Kalium is supporting Java, and can only be used with Apache Kafka as the underlying event bus. However, it is planned to have an implementation for other languages like Javascript and Python and to be used with AWS Kinesis as well.

Adding Kalium to your build

Kalium's Maven group ID is io.alkal and its artifact ID is kalium-kafka. To add a dependency on On using Maven, use the following:

<dependency>
  <groupId>io.alkal</groupId>
  <artifactId>kalium-kafka</artifactId>
  <version>0.0.1</version>
</dependency>

To add a dependency using Gradle:

dependencies {
  compile 'io.alkal:kalium-kafka:0.0.1'
}

Quick start

Sending Hello object between services

public class Hello {
    
    private String value;
    
    public Hello(String value) {
        this.value = value;
    }
    
    public String getValue() {
        return value;
    }
}

Service 1 - greeter

public class Greeter {

    public static void main(String[] args) {
        Kalium kalium = Kalium.Builder()
            .setQueue(new KaliumKafkaQueueAdapter("localhost:9092"))
            .build();
        kalium.start();
        Hello hello = new Hello("world");
        kalium.post(hello);
   }
}

Service 2- printing greeting on another service

public class HelloPrintingService {

    public static void main(String[] args) {
        Kalium kalium = Kalium.Builder()
            .setQueue(new KaliumKafkaQueueAdapter("localhost:9092"))
            .build();
        kalium.addReaction(new HelloReaction);
        kalium.start();
   }
}

public class HelloReaction{
    @On
    public void printHello(Hello hello) {
        System.out.println("Hello " + hello.getValue());
    }
}

contact me: [email protected]

io.alkal

alkal.io

Making software react

Versions

Version
0.0.4
0.0.3
0.0.2
0.0.1