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:
- 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
- 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
- Login to OpenShift Dashboard and create the
demo-eventingproject (oc new-project demo-eventing) - Create the Knative
Brokerwith thekn broker create default - Build the and deploy to OpenShift by activating the already defined
openshiftMaven profile:mvn clean package -Popenshift
!!! For those who don't want to deploy using Quarkus Kubernetes extension and Maven.
- Login to OpenShift Dashboard https://console-openshift-console.apps.qyt1tahi.eastus.aroapp.io/
- Create your project
- 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- 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
- Create
KafkaBindingfor 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:9092For 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:9092For 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- Create
KafkaSourceto get messages from Kafka and send them to the KnativeBroker
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- Create Knative
Triggerfor 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: /reserveFor 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: /reserveFor 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- Configure autoscaling for
payment-serviceandstock-service
Edit Knative Service YAML and add the following annotations:
annotations:
autoscaling.knative.dev/target: "50"
autoscaling.knative.dev/metric: "rps"- Change timeout for
order-service
Edit Knative Service YAML and change TICK_TIMEOUT env