Giter Club home page Giter Club logo

asc-lab / micronaut-microservices-poc Goto Github PK

View Code? Open in Web Editor NEW
487.0 54.0 171.0 17.32 MB

Very simplified insurance sales system made in a microservices architecture using Micronaut

Home Page: https://altkomsoftware.pl/en/blog/microservices-micronaut/

License: Apache License 2.0

Dockerfile 0.69% Java 72.22% JavaScript 2.05% HTML 1.35% Vue 12.48% Shell 1.68% Batchfile 1.38% Kotlin 1.86% TypeScript 6.02% CSS 0.29%
micronaut microservices microservices-architecture insurance consul kafka zipkin mongodb postgresql h2-database jwt jwt-auth

micronaut-microservices-poc's Introduction

ASCLAB Micronaut PoC - LAB Insurance Sales Portal

Build Status

This is an example of a very simplified insurance sales system made in a microservice architecture using Micronaut.

Comprehensive guide describing exactly the architecture, applied design patterns and technologies can be found on our blog in article Building Microservices with Micronaut.

We have recently upgraded to Java 14 (you must have JDK14 in order to build and run the project).

We encourage you to read, because in this README there is only a substitute for all information.

Other articles around microservices that could be interesting:

Architecture overview

Micronaut Microservices Architecture

  • agent-portal-gateway - Gateway pattern from EAA Catalog implementation.
    The complexity of “business microservices” will be hidden by using Gateway pattern. This component is responsible for the proper redirection of requests to the appropriate services based on the configuration. The frontend application will only communicate with this component. This component show usage of non-blocking http declarative clients.

  • payment-service - main responsibilities: create Policy Account, show Policy Account list, register in payments from bank statement file.
    This module is taking care of a managing policy accounts. Once the policy is created, an account is created in this service with expected money income. Payment-service also has an implementation of a scheduled process where CSV file with payments is imported and payments are assigned to policy accounts. This component shows asynchronous communication between services using Kafka and ability to create background jobs using Micronaut. It also features accessing database using JPA.

  • policy-service - creates offers, converts offers to insurance policies.
    In this service we demonstrated usage of CQRS pattern for better read/write operation isolation. This service demonstrates two ways of communication between services: synchronous REST based calls to pricing-service through HTTP Client to get the price, and asynchronous event based using Apache Kafka to publish information about newly created policies. In this service we also access RDBMS using JPA.

  • policy-search-service - provides insurance policy search.
    This module listens for events from Kafka, converts received DTOs to “read model” (used later in search) and saves this in database (ElasticSearch). It also exposes REST endpoint for search policies.

  • pricing-service - calculates price for selected insurance product.
    For each product a tariff should be defined. The tariff is a set of rules on the basis of which the price is calculated. MVEL language was used to define the rules. During the policy purchase process, the policy-service connects with this service to calculate a price. Price is calculated based on user’s answers for defined questions.

  • product-service - simple insurance product catalog.
    Information about products are stored in MongoDB. Each product has code, name, image, description, cover list and question list (affect the price defined by the tariff). This module shows usage of reactive Mongo client.

  • auth-service - JWT based authentication service, this services provides login functionality.
    Based on login and password users get authenticated and JWT token with their privileges is created and returned. This services shows built-in Micronaut support for JWT based security.

  • documents-service - Service build with kotlin. Responsible for generating pdf document when new policy event is received.

  • chat-service - Example WebSocket usage. Chat for salesman.

  • dashboard-service - Business dashboards that presents our agents sales results. Dashboard service subscribes to events of selling policies and index sales data in ElasticSearch. Then ElasticSearch aggregation framework is used to calculate sales stats like: total sales and number of policies per product per time period, sales per agent in given time period and sales timeline. Sales stats are nicely visualized using ChartJS.

  • web-vue - SPA application built with Vue.js and Bootstrap for Vue.

Each business microservice has also -api module (payment-service-api, policy-service-api etc.), where we defined commands, events, queries and operations.

In the picture you can also see the component internal-command-bus. This component is used internally by microservices if we want to use a CQRS pattern inside (simple example in OfferController in policy-service).

Building

This step requires Java 14 (JDK), Maven and Yarn.

For demo purposes build process is automated by a shell script. For Unix-based systems:

build-without-tests.sh

For Windows:

build-without-tests.bat

If you already run the necessary infrastructure (Kafka, Consul etc.), you should run build with all tests: For Unix-based systems:

build.sh

For Windows:

build.bat

Running for development

Prerequisites

  • docker
  • docker-compose

Windows users: make sure to set core.autocrlf false in git configuration before cloning this repository.

For Windows users, append below line C:\Windows\System32\drivers\etc\hosts:

127.0.0.1 kafkaserver

For frontend app running, you must add file .env.local based on .env-example .

Env

Automated deployment

To run the whole system on local machine just type:

docker-run.sh

Make sure you've first built the microservices! Check this. This script will provision required infrastructure and start all services. Setup is powered by docker-compose and configured via docker-compose.yml file.

Afterwards you need to add kafka cluster - either via web UI (Kafka Manager -> Cluster -> Add Cluster) or using provided script:

kafka-create-cluster.sh

At this point system is ready to use: http://localhost

Manual deployment

If you want to run services manually (eg. from IDE), you have to provision infrastructure with script from scripts folder:

infra-run.sh

Afterwards you need to add kafka cluster - either via web UI (Kafka Manager -> Cluster -> Add Cluster) or using provided script:

kafka-create-cluster.sh
  • Consul dashboard: http://localhost:8500
  • Zipkin dashboard: http://localhost:9411/zipkin/
  • Kafka Manager dashboard: http://localhost:9000/
  • JSReport dashboard: http://localhost:5488/

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

Check this;

Add POLICY template to JsReport

Zipkin

  1. Click "+".
  2. Type name "POLICY" and content from file policy.template.
  3. Commit changes.

Consul without our script

docker run -p 8500:8500 consul

Zipkin without our script

docker run -d -p 9411:9411 openzipkin/zipkin

Kafka without our script

Setup Kafka on Windows with this instruction.

JSReport without our script

docker run -p 5488:5488 jsreport/jsreport

OpenAPI/Swagger docs

agent-portal-gateway provides the API description.

You can go to URL: [http://localhost:8081/swagger/lab-insurance-sales-portal-api-1.0.yml][http://localhost:8081/swagger/lab-insurance-sales-portal-api-1.0.yml]

Add new microservice

Create new microservice with Micronaut CLI:

mn create-app pl.altkom.asc.lab.[SERVICE-NAME]-service -b maven

This command generate project in Java and Maven as build tool.

Examples

Sample users

  • admin / admin
  • jimmy.solid / secret
  • danny.solid / secret
  • agent1 / agent1

Chat

Chat

Sales Dashboard

Sales Dashboard

Tracing requests with Zipkin

Zipkin

Show topics on Kafka

Kafka

Show registered services in Consul

Consul

Show document templates in JS Report

JSReport

References

micronaut-microservices-poc's People

Contributors

arekros avatar azure-pipelines[bot] avatar grimmjo avatar khelman avatar kingzevin avatar rkusmierek avatar sdelamo avatar witek1902 avatar wojteksuwala 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  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  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  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  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  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  avatar

micronaut-microservices-poc's Issues

Error run docker-run.sh. Cannot start service mn-web-vue

Hi, I have a problem when i launch the docker-run:

ERROR: for mn-web-vue Cannot start service mn-web-vue: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: "/entrypoint.sh": stat /entrypoint.sh: no such file or directory": unknown

ERROR: for mn-web-vue Cannot start service mn-web-vue: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: "/entrypoint.sh": stat /entrypoint.sh: no such file or directory": unknown
ERROR: Encountered errors while bringing up the project.

ANy solutions for this problem? I have performed all the steps described

Thaks

[documents-service] org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread.

In documents-service, when a policy is paid, an error is raised: org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread. I've added the policy template in JSReport and committed.

14:28:54.569 [pool-2-thread-1] ERROR i.m.c.k.e.KafkaListenerExceptionHandler - Error processing record [Optional[ConsumerRecord(topic = policy-registered, partition = 0, leaderEpoch = null, offset = 3, CreateTime = 1598884133749, serialized key size = 36, serialized value size = 159, headers = RecordHeaders(headers = [], isReadOnly = false), key = [B@7dbe50be, value = pl.altkom.asc.lab.micronaut.poc.policy.service.api.v1.events.PolicyRegisteredEvent@7c3b26a3)]] for Kafka consumer [pl.altkom.asc.lab.micronaut.poc.documents.domain.PolicyRegisteredListener@3a66e52c] produced error: Could not obtain transaction-synchronized Session for current thread
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
	at io.micronaut.transaction.hibernate5.MicronautSessionContext.currentSession(MicronautSessionContext.java:100)
	at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:475)
	at io.micronaut.configuration.hibernate.jpa.TransactionalSessionInterceptor.intercept(TransactionalSessionInterceptor.java:56)
	at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:69)
	at io.micronaut.configuration.hibernate.jpa.TransactionalSession$Intercepted.persist(Unknown Source)
	at pl.altkom.asc.lab.micronaut.poc.documents.infrastructure.adapters.db.PolicyDocumentDb.add(PolicyDocumentDb.kt:20)
	at pl.altkom.asc.lab.micronaut.poc.documents.domain.PolicyRegisteredListener.onPolicyRegistered(PolicyRegisteredListener.kt:24)
	at pl.altkom.asc.lab.micronaut.poc.documents.domain.$PolicyRegisteredListenerDefinition$$exec1.invokeInternal(Unknown Source)
	at io.micronaut.context.AbstractExecutableMethod.invoke(AbstractExecutableMethod.java:146)
	at io.micronaut.core.bind.DefaultExecutableBinder$1.invoke(DefaultExecutableBinder.java:109)
	at io.micronaut.configuration.kafka.processor.KafkaConsumerProcessor.lambda$process$7(KafkaConsumerProcessor.java:498)
	at io.micronaut.scheduling.instrument.InvocationInstrumenterWrappedRunnable.run(InvocationInstrumenterWrappedRunnable.java:47)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

[Automated deployment] local machine problem with docker build step

I've found out that there is issue with command $ sh docker-run.sh

Building mn-documents-service
Step 1/4 : FROM openjdk:8u171-alpine3.7
8u171-alpine3.7: Pulling from library/openjdk
911c6d0c7995: Pull complete
4001add52a90: Pull complete
874028933da5: Pull complete
Digest: sha256:12e19d0dffa75ded3ab909e8c1966682b097f155ca0c2c88577445c64d6776d5
Status: Downloaded newer image for openjdk:8u171-alpine3.7
 ---> 1caad94162ef
Step 2/4 : RUN apk --no-cache add curl
 ---> Running in 7b456af061f8
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
(1/3) Installing libssh2 (1.8.2-r0)
(2/3) Installing libcurl (7.61.1-r2)
(3/3) Installing curl (7.61.1-r2)
Executing busybox-1.27.2-r11.trigger
OK: 100 MiB in 56 packages
Removing intermediate container 7b456af061f8
 ---> 8c3c977f7245
Step 3/4 : COPY target/documents-service*.jar documents-service.jar
ERROR: Service 'mn-documents-service' failed to build: COPY failed: no source files were specified

Is there any clue that can be helpful to fix it?

Elasticsearch container doesn't start on kubernetes

Elasticsearch version:
docker.elastic.co/elasticsearch/elasticsearch:6.4.2

logs:

[2018-10-18T09:05:09,530][INFO ][o.e.n.Node               ] [BXSDDvd] starting ...
[2018-10-18T09:05:09,762][INFO ][o.e.t.TransportService   ] [BXSDDvd] publish_address {172.17.0.6:9300}, bound_addresses {0.0.0.0:9300}
[2018-10-18T09:05:09,806][INFO ][o.e.b.BootstrapChecks    ] [BXSDDvd] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [1] bootstrap checks failed
[1]: memory locking requested for elasticsearch process but memory is not locked
[2018-10-18T09:05:09,850][INFO ][o.e.n.Node               ] [BXSDDvd] stopping ...
[2018-10-18T09:05:09,914][INFO ][o.e.n.Node               ] [BXSDDvd] stopped
[2018-10-18T09:05:09,921][INFO ][o.e.n.Node               ] [BXSDDvd] closing ...
[2018-10-18T09:05:09,971][INFO ][o.e.n.Node               ] [BXSDDvd] closed
[2018-10-18T09:05:09,976][INFO ][o.e.x.m.j.p.NativeController] Native controller process has stopped - no new native processes can be started

Contracts

Decouple services by removing shared libraries and applying API contracts.

Script to build all services

For demo purposes, we need a script to build all the services.
This can be in form of parent pom.xml or regular script that uses maven to build each service.

Docker network_mode: host supports only Linux

I am a Windows user.

When running docker-compose i can not access kafka manager via localhost:9000.

Here i found this info:

The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.

Is there an option to change docker files so they won't use network_mode: host ?

Also i found out - that i need to have Linux ending file (LF) instead of Windows default (CRLF) to keep container mn-web-vue running.

Unable to setup Kafka Cluster

I had no issues building and running the program until it was time to add a Kafka cluster. When running the kafka-create-cluster.sh file I received the following message:

  • Trying 127.0.0.1...
  • TCP_NODELAY set
  • Connection failed
  • connect to 127.0.0.1 port 29092 failed: Connection refused
  • Trying ::1...
  • TCP_NODELAY set
  • Connection failed
  • connect to ::1 port 29092 failed: Connection refused
  • Failed to connect to localhost port 29092: Connection refused
  • Closing connection 0

Any suggestions? Thanks.

Docker-compose does not expose 9000, 9092, 2181 ports

As documentation states now:

https://github.com/asc-lab/micronaut-microservices-poc#automated-deployment

Afterwards you need to add kafka cluster - either via web UI (Kafka Manager -> Cluster -> Add Cluster) or using provided script:

kafka-create-cluster.sh

To be able to do that you must have connection to kafka manager via localhost:9000.

If you execute now docker-compose up you see that this port is not exposed:

2

To expose this port remove:

network_mode: host

from kafka_manager container definition.

After this change you see that port 9000 is exposed:

1

I will make pull request regarding this issue. This also need to be fix for other containers like:
kafkaserver.

Still there is issue after visiting localhost:9200 and executing script kafka-create-cluster.sh

chrome_2019-07-17_16-13-22

I am a Windows user.

Elasticsearch container doesn't start on Kubernetes hosted in the cloud

Elasticsearch version:
docker.elastic.co/elasticsearch/elasticsearch:6.4.2

logs:

[2018-11-06T17:01:53,087][INFO ][o.e.n.Node               ] [yHdqr9S] starting ...
[2018-11-06T17:01:53,475][INFO ][o.e.t.TransportService   ] [yHdqr9S] publish_address {10.48.4.11:9300}, bound_addresses {[::]:9300}
[2018-11-06T17:01:53,510][INFO ][o.e.b.BootstrapChecks    ] [yHdqr9S] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2018-11-06T17:01:53,556][INFO ][o.e.n.Node               ] [yHdqr9S] stopping ...
[2018-11-06T17:01:53,580][INFO ][o.e.n.Node               ] [yHdqr9S] stopped
[2018-11-06T17:01:53,581][INFO ][o.e.n.Node               ] [yHdqr9S] closing ...
[2018-11-06T17:01:53,605][INFO ][o.e.n.Node               ] [yHdqr9S] closed
[2018-11-06T17:01:53,609][INFO ][o.e.x.m.j.p.NativeController] Native controller process has stopped - no new native processes can be started

Add CI/CD

Add config for CI/CD (for example Azure DevOps).

Get rid of Lombok dependency

It is more like question than issue. I would prefer the project without dependency on Lombok since it forces me to install additional IDE plugins.

Are you interested in PR that replaces Lombok with regular Java code?

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.