Skip to content

onobc/rabbitmq-transaction-processing

 
 

Repository files navigation

What this is all about

This code demonstrates best practices of reliable messaging and caching by creating two Kubernetes-ready microservices written in Spring Boot 3.2.1:

Architecture

Architecture

Configuration

Some properties (e.g., the RabbitMQ or GemFire connection string and credentials) require configuration.

  • When run locally, the configuration properties are taken from application-default.properties|yaml file.
  • When run in Kubernetes, the Helm deploys configmaps containing the configuration, see the k8s/helm/chart/[chart-name]/templates/configmap.yaml file. The app then is running under the kubernetes profile and reads the configuraion from the configmaps.

Prerequisites

Create a Kubernetes cluster

Use a distribution of your choice. e.g. kind if for development purposes. On the cluster, create and configure:

Install Helm

Helm is a package manager for Kuberntes used to package our microservices. Follow the guide

Install RabbitMQ

Follow the guide

Install GemFire

Install JDK

Used to build the artifacts from the source code.

Enable the RabbitMQ Consistent Hash Plugin

The Consistent Hash Exchange is used to distribute workload to multiple queues backed by mutiple CPU cores.

To enable the plugin, assuming the k8s rabbitmq namespace is rabbitmq-system, and the number of RabbitMQ pods is 3:

kubectl -n rabbitmq-system exec -it tanzu-rabbitmq-server-0 -- rabbitmq-plugins enable rabbitmq_consistent_hash_exchange
kubectl -n rabbitmq-system exec -it tanzu-rabbitmq-server-1 -- rabbitmq-plugins enable rabbitmq_consistent_hash_exchange
kubectl -n rabbitmq-system exec -it tanzu-rabbitmq-server-2 -- rabbitmq-plugins enable rabbitmq_consistent_hash_exchange

Running Services locally

From the CLI or the IDE, do:

Transaction Ingestion Service

./gradlew :transaction-ingestion-service:bootRun

Notification Service

./gradlew :notification-service:bootRun

Building the Helm charts and deploying the microservices to Kubernetes

Each microservice has a corresponding build-and-deploy-k8s.sh script file. You may need to adjust the following variables:

  • namespace: the k8s namespace used to deploy the artifacts
  • registry: your local or private Docker registry URL.

Appendix

Connecting to GemFire on K8s

# connect to a locator pod:
kubectl -n YOUR-GEMFIRE-NAMESPACE exec -it YOUR-GEMFIRE-CLUSTER-locator-0 -- gfsh

# type in gfsh:
connect --locator=YOUR-GEMFIRE-CLUSTER-locator-0.YOUR-GEMFIRE-CLUSTER-locator.YOUR-GEMFIRE-NAMESPACE.svc.cluster.local[10334] --security-properties-file=/security/gfsecurity.properties

For example, if the k8s namespace is tanzu-gemfire, and the gemfire cluster is named gemfire-cluster, it is:

# connect to a locator pod:
kubectl -n tanzu-gemfire exec -it gemfire-cluster-locator-0 -- gfsh

# type in gfsh:
connect --locator=gemfire-cluster-locator-0.gemfire-cluster-locator.tanzu-gemfire.svc.cluster.local[10334] --security-properties-file=/security/gfsecurity.properties

Running microservices in Docker

Example:

# build
docker build -t transaction-ingestion-service .

# run
docker run --rm -p8081:8080 transaction-ingestion-service

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 75.3%
  • Smarty 14.0%
  • Shell 6.2%
  • Dockerfile 4.5%