Giter Club home page Giter Club logo

sample-quarkus-serverless-kafka's Introduction

Serverless with Knative Eventing and Quarkus Twitter

CircleCI

SonarCloud Bugs Coverage Lines of Code

Getting Started

Currently, you may find here some examples of microservices implementation using different projects from Quarkus. All the examples are divided into the branches and described in a separated articles on my blog. Here's a full list of available examples:

  1. Using Knative Serving and Eventing components with Quarkus and Kafka to build event-driven microservices architecture in declarative way. The example is available in the branch master. A detailed guide may be found in the following article: Knative Eventing with Kafka and Quarkus
  2. Update to the Knative Eventing focusing on KafkaSink, OpenShift and REST client interaction with event-mesh. A detailed guide may be found in the following article: Serverless on OpenShift with Knative, Quarkus and Kafka

Usage

Architecture

Run with Quarkus

  1. Login to OpenShift Dashboard and create the demo-eventing project (oc new-project demo-eventing)
  2. Create the Knative Broker with the kn broker create default
  3. Build the and deploy to OpenShift by activating the already defined openshift Maven profile: mvn clean package -Popenshift

Test on OpenShift

!!! For those who don't want to deploy using Quarkus Kubernetes extension and Maven.

  1. Login to OpenShift Dashboard https://console-openshift-console.apps.qyt1tahi.eastus.aroapp.io/
  2. Create your project
  3. Create Knative Broker
apiVersion: eventing.knative.dev/v1
kind: Broker
metadata:
  annotations:
    eventing.knative.dev/broker.class: MTChannelBasedBroker
  name: default
spec:
  config:
    apiVersion: v1
    kind: ConfigMap
    name: config-br-default-channel
    namespace: knative-eventing
  1. Deploy applications

order-service -> quay.io/pminkows/order-service. Set env KAFKA_TOPIC, TICK_TIMEOUT
stock-service -> quay.io/pminkows/stock-service. Set env KAFKA_TOPIC
payment-service -> quay.io/pminkows/payment-service. Set env KAFKA_TOPIC

  1. Create KafkaBinding for each application to inject Kafka address (only older versions of Kafka)

For stock-service:

apiVersion: bindings.knative.dev/v1beta1
kind: KafkaBinding
metadata:
  name: kafka-binding-stock
spec:
  subject:
    apiVersion: serving.knative.dev/v1
    kind: Service
    name: stock-service
  bootstrapServers:
    - my-cluster-kafka-bootstrap.kafka:9092

For payment-service:

apiVersion: bindings.knative.dev/v1beta1
kind: KafkaBinding
metadata:
  name: kafka-binding-payment
spec:
  subject:
    apiVersion: serving.knative.dev/v1
    kind: Service
    name: payment-service
  bootstrapServers:
    - my-cluster-kafka-bootstrap.kafka:9092

For order-service:

apiVersion: bindings.knative.dev/v1beta1
kind: KafkaBinding
metadata:
  name: kafka-binding-order
spec:
  subject:
    apiVersion: serving.knative.dev/v1
    kind: Service
    name: order-service
  bootstrapServers:
    - my-cluster-kafka-bootstrap.kafka:9092
  1. Create KafkaSource to get messages from Kafka and send them to the Knative Broker
apiVersion: sources.knative.dev/v1beta1
kind: KafkaSource
metadata:
  name: kafka-source-to-broker
spec:
  bootstrapServers:
    - my-cluster-kafka-bootstrap.kafka:9092
  topics:
    - <your-order-events-topic>
    - <your-reserve-events-topic>
  sink:
    ref:
      apiVersion: eventing.knative.dev/v1
      kind: Broker
      name: default
  1. Create Knative Trigger for applications

For stock-service:

apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
  name: stock-trigger
spec:
  broker: default
  filter:
    attributes:
      source: /apis/v1/namespaces/<your-namespace>/kafkasources/kafka-source-to-broker#<your-topic>
      type: dev.knative.kafka.event
  subscriber:
    ref:
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: stock-service
    uri: /reserve

For payment-service:

apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
  name: payment-trigger
spec:
  broker: default
  filter:
    attributes:
      source: /apis/v1/namespaces/<your-namespace>/kafkasources/kafka-source-to-broker#<your-topic>
      type: dev.knative.kafka.event
  subscriber:
    ref:
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: payment-service
    uri: /reserve

For order-service:

apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
  name: order-trigger
spec:
  broker: default
  filter:
    attributes:
      source: /apis/v1/namespaces/<your-namespace>/kafkasources/kafka-source-to-broker#<your-topic>
      type: dev.knative.kafka.event
  subscriber:
    ref:
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: order-service
    uri: /confirm
  1. Configure autoscaling for payment-service and stock-service

Edit Knative Service YAML and add the following annotations:

      annotations:
        autoscaling.knative.dev/target: "50"
        autoscaling.knative.dev/metric: "rps"
  1. Change timeout for order-service

Edit Knative Service YAML and change TICK_TIMEOUT env

sample-quarkus-serverless-kafka's People

Contributors

piomin avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sample-quarkus-serverless-kafka's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

circleci
.circleci/config.yml
  • cimg/openjdk 21.0.2
  • maven 1.4.1
maven
order-service/pom.xml
payment-service/pom.xml
pom.xml
  • io.quarkus.platform:quarkus-maven-plugin 3.10.1
  • org.apache.maven.plugins:maven-compiler-plugin 3.13.0
  • org.apache.maven.plugins:maven-surefire-plugin 3.2.5
  • io.quarkus.platform:quarkus-maven-plugin 3.10.1
  • org.apache.maven.plugins:maven-compiler-plugin 3.13.0
  • org.apache.maven.plugins:maven-surefire-plugin 3.2.5
  • io.quarkus.platform:quarkus-bom 3.10.1
  • io.quarkus.platform:quarkus-maven-plugin 3.10.1
  • org.apache.maven.plugins:maven-surefire-plugin 3.2.5
stock-service/pom.xml

  • Check this box to trigger a request for Renovate to run again on this repository

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.