Demo for Dapr v1.x

Overview

Demo for Dapr v1.x

1. Demo Services

  1. dapr-demo-proto: protocol buffer definition, contains the generated code.

  2. dapr-demo-order: product java service, serve on 5050

  • provide http method /create to create a new order.
    • request dapr-demo-product http /get to query product service
    • request dapr-demo-pay grpc pay to pay order
  • listen topic pay_event in raw data format
  • listen topic pay_result in CloudEvent format
  1. dapr-demo-product: product java service, serve on 5051

    • provide http method /get to response product price.
  2. dapr-demo-pay: pay java service, serve on 5052

  • provide grpc pay method to pay an order
    • publish paying event to topic pay_event
    • request dapr-demo-bank grpc trans to finish a pay transaction
  • listen topic trans_event
    • publish success event to topic pay_result
  1. dapr-demo-bank: bank java service, serve on 5053
  • provide grpc trans method to finish a pay transaction
    • publish success event to topic trans_event
  1. dapr-demo-discount: discount golang service, serve on 5054

2. prepare

The version of protocol buffer and grpc should match the dapr version, which can be found at https://github.com/dapr/java-sdk/blob/master/pom.xml.

  • protocol buffer version: 3.13.0
  • grpc version: 1.39.0

2.1. install protoc

# ref: https://google.github.io/proto-lens/installing-protoc.html
# ---- mac
# PROTOC_ZIP=protoc-3.13.0-osx-x86_64.zip
# ---- linux
PROTOC_ZIP=protoc-3.13.0-linux-x86_64.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.13.0/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
sudo unzip -o $PROTOC_ZIP -d /usr/local 'include/*'
sudo chmod +x /usr/local/bin/protoc
rm -f $PROTOC_ZIP

2.2. install protoc-java-plugin

# ref: https://github.com/grpc/grpc-java/tree/master/compiler
# 1. Navigate to https://mvnrepository.com/artifact/io.grpc/protoc-gen-grpc-java
# 2. Click into a version
# 3. Click "Files"

# ---- mac
# wget https://repo1.maven.org/maven2/io/grpc/protoc-gen-grpc-java/1.39.0/protoc-gen-grpc-java-1.39.0-osx-x86_64.exe
# sudo mv protoc-gen-grpc-java-1.39.0-osx-x86_64.exe /usr/local/bin/protoc-gen-grpc-java-1.39.0
# ---- linux
wget https://repo1.maven.org/maven2/io/grpc/protoc-gen-grpc-java/1.39.0/protoc-gen-grpc-java-1.39.0-linux-x86_64.exe
sudo mv protoc-gen-grpc-java-1.39.0-linux-x86_64.exe /usr/local/bin/protoc-gen-grpc-java-1.39.0
sudo chmod +x /usr/local/bin/protoc-gen-grpc-java-1.39.0

2.2. install protoc-golang-plugin

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

3. generate grpc java code

make proto-gen

4. How To Run

4.1. run dapr demo in self host

50005/tcp dapr_placement #6ff1e82bd6f1 openzipkin/zipkin "start-zipkin" 2 months ago Up 37 minutes (healthy) 9410/tcp, 0.0.0.0:9411->9411/tcp dapr_zipkin # 816b739bf523 redis "docker-entrypoint.s…" 2 months ago Up 37 minutes 0.0.0.0:6379->6379/tcp dapr_redis make build-golang build-java sh run-self-host.sh ">
# install dapr
wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash
# or download directly: https://github.com/dapr/cli/releases/download/v1.6.0/dapr_darwin_amd64.tar.gz

# dapr uninstall
dapr init
dapr --version
# CLI version: 1.6.0
# Runtime version: 1.6.0


docker ps
#CONTAINER ID   IMAGE               COMMAND                  CREATED          STATUS                    PORTS                              NAMES
#73627103ac9d   daprio/dapr:1.6.0   "./placement"            30 minutes ago   Up 30 minutes             0.0.0.0:50005->50005/tcp           dapr_placement
#6ff1e82bd6f1   openzipkin/zipkin   "start-zipkin"           2 months ago     Up 37 minutes (healthy)   9410/tcp, 0.0.0.0:9411->9411/tcp   dapr_zipkin
# 816b739bf523   redis               "docker-entrypoint.s…"   2 months ago     Up 37 minutes             0.0.0.0:6379->6379/tcp             dapr_redis

make build-golang build-java

sh run-self-host.sh

4.2. run dapr demo in kubernetes

install tools:

# install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
echo "$(<kubectl.sha256) kubectl" | sha256sum --check
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client

# install helm
# find the latest version from https://mirrors.huaweicloud.com/helm
wget https://mirrors.huaweicloud.com/helm/v3.7.1/helm-v3.7.1-linux-amd64.tar.gz
tar -xvf helm-v3.7.1-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/

# https://docs.dapr.io/operations/hosting/kubernetes/cluster/setup-minikube/
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
minikube config set vm-driver docker
minikube start --cpus=4 --memory=4096

install dapr in kubernetes:

# ----------------------------------
# install dapr cli using command (NOT required if already installed using helm)
wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash
# The -k flag initializes Dapr on the Kubernetes cluster in your current context.
# Setup & configure mutual TLS: https://docs.dapr.io/operations/security/mtls/
# If custom certificates have not been provided, Dapr will automatically create and persist self signed certs valid for one year. In Kubernetes, 
# the certs are persisted to a secret that resides in the namespace of the Dapr system pods, accessible only to them.
dapr init -k  --enable-mtls=false
# Uninstall Dapr on Kubernetes with CLI  
# dapr uninstall -k
kubectl get pods --namespace dapr-system
dapr status -k
# ----------------------------------

install dapr in kubernetes using helm

install redis:

redis-state.yaml apiVersion: dapr.io/v1alpha1 kind: Component metadata: name: statestore namespace: default spec: type: state.redis version: v1 metadata: - name: redisHost value: redis-master.default.svc.cluster.local:6379 - name: redisPassword secretKeyRef: name: redis key: redis-password EOF cat < redis-pubsub.yaml apiVersion: dapr.io/v1alpha1 kind: Component metadata: name: pubsub namespace: default spec: type: pubsub.redis version: v1 metadata: - name: redisHost value: redis-master.default.svc.cluster.local:6379 - name: redisPassword secretKeyRef: name: redis key: redis-password EOF kubectl apply -f redis-state.yaml kubectl apply -f redis-pubsub.yaml kkubectl get components # NAME AGE # pubsub 26d # statestore 26d">
# Install Redis into your cluster
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm install redis bitnami/redis
#    redis-master.default.svc.cluster.local for read/write operations (port 6379)
#    redis-replicas.default.svc.cluster.local for read-only operations (port 6379)
# export REDIS_PASSWORD=$(kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" | base64 --decode)
# see the Redis containers now running in your cluster
kubectl get pods
# NAME               READY   STATUS    RESTARTS      AGE
# redis-master-0     1/1     Running   3 (27m ago)   27d
# redis-replicas-0   1/1     Running   5 (27m ago)   27d
# redis-replicas-1   1/1     Running   5 (27m ago)   27d
# redis-replicas-2   1/1     Running   5 (27m ago)   27d

cat <<EOF > redis-state.yaml 
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: statestore
  namespace: default
spec:
  type: state.redis
  version: v1
  metadata:
  - name: redisHost
    value: redis-master.default.svc.cluster.local:6379
  - name: redisPassword
    secretKeyRef:
      name: redis
      key: redis-password
EOF


cat <<EOF > redis-pubsub.yaml 
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: pubsub
  namespace: default
spec:
  type: pubsub.redis
  version: v1
  metadata:
  - name: redisHost
    value: redis-master.default.svc.cluster.local:6379
  - name: redisPassword
    secretKeyRef:
      name: redis
      key: redis-password
EOF

kubectl apply -f redis-state.yaml
kubectl apply -f redis-pubsub.yaml

kkubectl get components
# NAME         AGE
# pubsub       26d
# statestore   26d

build demo docker images:

# ---------- MUST execute before eval minikube docker-env
docker run --rm -v $(pwd):/projectdir \
-v ${GOPATH}/src:/go/src \
-v ${GOPATH}/pkg:/go/pkg \
-w /projectdir \
-e GOOS="linux" \
-e GOARCH="amd64" \
-e CGO_ENABLED=0 \
-e GOPROXY=https://goproxy.cn \
golang:1.17.3-buster \
make build-golang

docker run --rm -v $(pwd):/projectdir \
-v ~/.m2:/root/.m2 \
-w /projectdir \
maven:3-openjdk-11 \
mvn clean package

using packages build in previous step to build docker images:

# use minikube docker registry
eval $(minikube -p minikube docker-env)
# build project images
make build-docker

run demo in kubernetes:

sh run-in-kubernetes.sh
You might also like...

Spring testcontainers demo

Getting Started Reference Documentation For further reference, please consider the following sections: Official Apache Maven documentation Spring Boot

Feb 16, 2022

Spring-boot application to demo JVM HEAP and Native memory leak

Description This repo can be used as demo repo for finding memory leaks. Example spring-boot project to show how to find and fix JVM HEAP memory leak

Jul 22, 2022

The project is a simple vulnerability Demo environment written by SpringBoot

The project is a simple vulnerability Demo environment written by SpringBoot

The project is a simple vulnerability Demo environment written by SpringBoot. Here, I deliberately wrote a vulnerability environment where there are arbitrary file uploads, and then use the `scan` attribute in the loghack configuration file to cooperate with the logback vulnerability to implement RCE.

Dec 14, 2022

Demo Repo for our CDC-based Strangler Fig Pattern Session @ VoxxedDays Romania 2021

Strangler Fig Pattern Demo Build applications Before being able to spin up the docker-compose based demo environment please make sure to successfully

Feb 20, 2022

Spring for GraphQL demo project with a Vue frontend.

Spring Books - Hello GraphQL This is a demo project that will introduce you to [https://spring.io/projects/spring-graphql](Spring for GraphQL). The Sp

Dec 2, 2022

A demo of Rongcloud uniapp sdk integration for compiling debug-apk in Android Studio

Rongcloud-uniapp-sdk-demo A demo of Rongcloud uniapp sdk integration for compiling debug-apk in Android Studio 这是一个为了给uniapp在Android平台打出debug-apk的demo

Oct 13, 2021

Google's ML-Kit-Vision demo (android) for pre encoded video.

Google's ML-Kit-Vision demo (android) for pre encoded video.

Android ML Kit Vision demo with Video Google's ML-Kit-Vision demo (android) for pre encoded video. Demos for camera preview and still image are also i

Dec 29, 2022

Euphony Demo for patients and assistants in case of an emergency.

Euphony Demo for patients and assistants in case of an emergency.

sound-helper Eutophia sample project Overview sound-helper is a sample application using the euphony Acoustic Data Telecommunication Library. This app

Sep 6, 2021

The Distributed Application Runtime (Dapr) provides APIs that simplify microservice connectivity

The Distributed Application Runtime (Dapr) provides APIs that simplify microservice connectivity

Quarkus - Dapr Introduction What is Quarkus? Traditional Java stacks were engineered for monolithic applications with long startup times and large mem

Jan 5, 2023

Flink Demo

Flink Demo

flink-demo minimum code just run flink-ds-connector DataStream API usage kafka es jdbc file row string parquet avro avro custom avro flink-sql-connect

Dec 4, 2022

Demo for schema references feature on the Confluent Schema Registry

Schema references demos This project aims to showcase the schema references feature on Confluent Schema Registry. Two distinct use case are considered

Sep 5, 2022

TapJacking Attacks Demo

TapJacking-Attacks "TapJacking Attacks, a thorough guide" Demostration Code Part 1 https://valsamaras.medium.com/tapjacking-attacks-a-thorough-guide-2

Oct 29, 2022

A scale demo of Neo4j Fabric spanning up to 1129 machines/shards running a 100TB (LDBC) dataset with 1.2tn nodes and relationships.

A scale demo of Neo4j Fabric spanning up to 1129 machines/shards running a 100TB (LDBC) dataset with 1.2tn nodes and relationships.

Demo application instructions Overview This repository contains the code necessary to reproduce the results for the Trillion Entity demonstration that

Nov 23, 2022

HUAWEI 3D Modeling Kit project contains a sample app. Guided by this demo, you will be able to implement full 3D Modeling Kit capabilities, including 3D object reconstruction and material generation.

HUAWEI 3D Modeling Kit Sample English | 中文 Introduction This project includes apps developed based on HUAWEI 3D Modeling Kit. The project directory is

Jan 1, 2023

Open API demo for CloudQuery

open-api-demo This project is an example for CloudQuery Community, which can assist community users in code development such as organizational structu

Jan 4, 2023

Geektime Todo is a demo todo project for Geektime column.

Geektime Todo 简介 这是《极客时间》专栏的 Todo 项目示例。 基本用法 生成 IDEA 工程 ./gradlew idea 检查 ./gradlew check 数据库迁移 ./gradlew flywayMigrate 生成构建产物 ./gradlew build 生成发布包 对

Oct 20, 2022

Contains the demo projects for S1 Application Modernization Breakout

Application Modernization Spring One 2021 This repository contains the projects that were demoed during the Application Modernization breakout discuss

Jan 24, 2022

A demo shopping cart Java Akka Serverless

shopping-cart-java-akka-serverless This project is an Akka Serverless service that demonstrates a simple shopping cart implemented as an Akka Serverle

Dec 3, 2021

source code of the live coding demo for "Building resilient and scalable API backends with Apache Pulsar and Spring Reactive" talk held at ApacheCon@Home 2021

reactive-iot-backend The is the source code of the live coding demo for "Building resilient and scalable API backends with Apache Pulsar and Spring Re

Jan 13, 2022
Owner
望哥
golang/java/devops/agile
望哥
Geektime Todo is a demo todo project for Geektime column.

Geektime Todo 简介 这是《极客时间》专栏的 Todo 项目示例。 基本用法 生成 IDEA 工程 ./gradlew idea 检查 ./gradlew check 数据库迁移 ./gradlew flywayMigrate 生成构建产物 ./gradlew build 生成发布包 对

Zheng Ye 53 Oct 20, 2022
A demo shopping cart Java Akka Serverless

shopping-cart-java-akka-serverless This project is an Akka Serverless service that demonstrates a simple shopping cart implemented as an Akka Serverle

Hugh McKee 7 Dec 3, 2021
source code of the live coding demo for "Building resilient and scalable API backends with Apache Pulsar and Spring Reactive" talk held at ApacheCon@Home 2021

reactive-iot-backend The is the source code of the live coding demo for "Building resilient and scalable API backends with Apache Pulsar and Spring Re

Lari Hotari 4 Jan 13, 2022
Apache Log4j2 CVE-2021-44228 RCE Demo with RMI and LDAP

CVE-2021-44228-Demo 利用 CVE-2021-44228,通过 RMI 和 LDAP 两种方式远程注入代码的示例。 Exploit class from RMI Server loaded Hello, ${jndi:rmi://127.0.0.1:1099/exploit} Ex

Zhuang Ma 2 Dec 14, 2021
Representational State Transfer + Structured Query Language(RSQL): Demo application using RSQL parser to filter records based on provided condition(s)

Representational State Transfer + Structured Query Language: RSQL Demo application using RSQL parser to filter records based on provided condition(s)

Hardik Singh Behl 9 Nov 23, 2022
Hexagonal Architecture Demo Project about Ticketing and Payment

This project is a sample production-ready implementation for demonstrating the power of Hexagonal Architecture (aka Ports And Adapters Pattern) written in Java.

Alican Akkuş 382 Jan 1, 2023
A short demo of CVE-2021-44228

sample-ldap-exploit A short demo of CVE-2021-44228 Build $ mvn clean verify Run Attacker $ java \ -cp 'attacker/target/sample-attacker.jar:attacker

Philip Oswald 6 Oct 19, 2022
Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker.

spring-microservice Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker. Arc

null 4 Sep 13, 2022
Spring Boot ECommerce Demo

springboot-ecommerce2 Things todo list Clone this repository: git clone https://github.com/hendisantika/springboot-ecommerce2.git Navigate to the fold

Hendi Santika 5 Aug 30, 2022
Microservices with Spring Boot and Kafka Demo Project

Example microservices showing how to use Kafka and Kafka Streams with Spring Boot on the example of distributed transactions implementations with the SAGA pattern

Piotr Mińkowski 98 Jan 7, 2023