This repository contains CQRS implementation in Java

Overview

CQRS Design Pattern Java

This repository contains CQRS implementation in Java. I've written this code-base step by step on Medium that is my Turkish content as called "Java ile CQRS Design Pattern | Docker, Elasticsearch, RabbitMQ, Spring, MySQL"

1_n3zJulJ4aZA1_tVCjJ9SBw

Setup

There are several basic steps below that we need to execute.

Docker Compose && Environment

Firstly, we need executing docker-compose.yml file, that is given below, due to setuping environment tech. Compose file is already here. docker-compose.yml

version: "3.9"

services:
  database:
    container_name: classifieds_mysql_container
    image: mysql:latest
    restart: always
    ports:
      - "3307:3306"
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: classifieds
      MYSQL_USER: user
      MYSQL_PASSWORD: password
    volumes:
      - mysql_database:/var/lib/mysql

  rabbitmq:
    container_name: classifieds_rabbitmq_container
    image: rabbitmq:3-management
    ports:
      - "5672:5672"
      - "15672:15672"

  elasticsearch:
    container_name: classifieds_elasticsearch
    image: docker.elastic.co/elasticsearch/elasticsearch:7.15.0
    volumes:
      - esdata:/usr/share/elasticsearch/data
    environment:
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.type=single-node
    logging:
      driver: none
    ports:
      - "9300:9300"
      - "9200:9200"

volumes:
  mysql_database:
  esdata:
docker-compose up

MySQL Database Table

After executing docker-compose file we need creating classified, that is a entity we use during the application, table on MySQL. Database connection information is already defined in docker-compose.yml file, after the MySQL connection we use this schema that is below.

CREATE TABLE `classified` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `title` varchar(100) DEFAULT NULL,
  `price` double DEFAULT NULL,
  `detail` text,
  `categoryId` bigint DEFAULT NULL,
  PRIMARY KEY (`id`)
) AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

Elasticsearch Index Creating And Mapping

We need create index on Elasticsearch because of representing database table on it. If you need checking Elasticsearch container status, you may use cURL code that is stay below.

curl -XGET "http://localhost:9200/_cat/health?format=json&pretty"

Create Index with mapping on Elasticsearch:

curl --location --request PUT 'http://localhost:9200/classifieds' \
--header 'Content-Type: application/json' \
--data-raw '{
    "settings": {
        "index": {
            "number_of_shards": 1,
            "number_of_replicas": 1
        }
    },
    "mappings": {
        "properties": {
            "id": {
                "type": "long"
            },
            "title": {
                "type": "text"
            },
            "price": {
                "type": "double"
            },
            "detail": {
                "type": "text"
            },
            "categoryId": {
                "type": "long"
            }
        }
    }
}'

We will see mapping on Elasticsearch if there is no any error. We may use this cURL code that is below for showing mapping.

curl -XGET "http://localhost:9200/classifieds/_mapping?pretty&format=json"

It show use created index's mapping.

RabbitMQ

We've bound RabbitMQ port in docker-compose file then we've used default RabbitMQ port, we may need checking RabbitMQ status, we are able to go this link to show RabbitMQ dashboard. http://localhost:15672

Usages

Sending request to api then creating data on MySQL then sending RabbitMQ event that will update Elasticsearch:

curl --location --request POST 'http://localhost:8080/classifieds' \
--header 'Content-Type: application/json' \
--data-raw '{
    "title": "Macbook Pro 2019",
    "detail": "Sahibinden çok temiz Macbook Pro 2019.",
    "price": 27894,
    "categoryId": 47
}'

Reading classified list from Elasticsearch:

curl --location --request GET 'http://localhost:8080/classifieds'
You might also like...

This repository contains my first project of Suven Internship.

This repository contains my first project of Suven Internship.

Consumer-Loan-Assistant PROBLEM STATEMENT (Ever wonder just) How much those credit card accounts are costing you? ABSTRACT This project will help you

Sep 16, 2022

This project contains a full example of an application developed using Spring Boot and GraphQL within the Java.

Spring boot GraphQL Example This project contains a full example of an application developed using GraphQL within the Java. The project includes a com

Jul 20, 2022

It contains a simple program to apply basic arithmetic operations in Morse code

Morse-Calculator By Mohamad Farag F. Makkawi This project falls under DSL (Domain Specific Language) . the Input is an equation in which simple arithm

Apr 29, 2022

WaterCore - It's a Core, for SpigotPlugins, that contains some other API's

WaterCore - It's a Core, for SpigotPlugins, that contains some other API's (From other Developers)

May 9, 2022

This repo contains all the materials for placement as well as Practical lab codes for all subjects and notes. For students graduating in 2023

UEMK_PLACEMENT_2023 This repo contains all the materials for placement as well as Practical lab codes for all subjects and notes. For students graduat

Mar 5, 2022

A DJL Algorithm used to detect if a Image contains a person such as Dream, Sapnap, George Not Found, TommyInnit, Tubbo or Ranboo. This Project has been created for a YouTube Video which is not yet finished, and neither is the Algorithm.

PissAI Personal Individuality Security Service Artificial Intelligence A DJL Algorithm used to detect if an Image contains a person such as Dream, Sap

Nov 19, 2022

This project contains many sample codes for demonstrating the usage of some common design patterns.

STUDY COMMON DESIGN PATTERNS 1. About this project This project contains many sample codes for demonstrating the usage of the following design pattern

Jan 2, 2023

Proj that contains code for merging files' data into one

Proj that contains code for merging files' data into one

Merge System Program that's written on Java for merging data (int or string types) of files (preferably .txt) into one file. Merge System Note: progra

Nov 27, 2022

Daily mail subscription implementation using Java Spring-boot and Quartz Scheduler

Daily Mail Subscription Service POC Implemented using Java Spring-boot and Quartz Scheduler Working Application Exposing 3 endpoints /subscription/cre

Jun 3, 2022
Owner
Yusuf Yılmaz
Software Engineer at sahibinden.com
Yusuf Yılmaz
This repository contains Java programs to become zero to hero in Java. Programs related to each and every concep are present from easy to intermidiate level.

Learn Java Programming In this repository you will find topic wise programs of java from basics to intermediate. This follows topic wise approach that

Sahil Batra 15 Oct 9, 2022
This repository contains examples of modern Java features that appear in various videos I'm creating for my courses at Vanderbilt.

This repository contains examples of modern Java features that appear in various videos I'm creating for my courses at Vanderbilt. It's organized into

Douglas C. Schmidt 7 Dec 1, 2022
A repository that contains the backend part of the Human Resources Management System.

Human Resources Management System Backend A human resources management system is a form of human resources (HR) software that combines several systems

Bulent Baris Kilic 24 Dec 26, 2022
This repository is for Todo application. This contains the Backend part of the application.

Todo Application 개요(Abstract) 개인용 할일 목록 리스트 앱플리케이션 구축 (Personal Todo List Application) 목적 1. React.js기초, AWS서버 활용, 스프링 부트 공부 목적으로 프로젝트 시작했습니다.

Thom 3 Jan 8, 2022
This repository contains the source code for a Product Comparison solution

Product Comparison Installation Guide This repository contains the source code for a Product Comparison solution. Please report any issues here. Insta

Mărgărit Marian Cătălin 8 Dec 5, 2022
This repository contains all the code developed during lessions of Foundations of Informatics T2.

If you're using the content of this Repostory, please consider to Watch or Star it in order to help tracking how many people are drawing on it. Founda

null 7 Nov 24, 2022
This repository contains solutions to all the Bit Manipulations problems and coding challenges

This repository contains solutions to all the Bit Manipulations problems and coding challenges. I have also written a course on how to solve problems using bit manipulation. You can visit it here: https://www.educative.io/courses/bit-manipulation (Grokking Bit Manipulation For Coding Interviews)

Gopi Gorantala 8 Nov 15, 2022
This repository contains the code for the Runescape private server project, and this repo is soley maintained by @Avanae and @ThePolyphia and @Xeveral

Runescape: The private server project. A Runescape private server based on the 2009 era. This repository contains the code for the Runescape private s

ProjectArchitecture 4 Oct 1, 2022
This repository contains source code examples to support my course Spring Data JPA and Hibernate Beginner to Guru

Spring Data JPA - Spring Data JPA This repository contains source code examples to support my course Spring Data JPA and Hibernate Beginner to Guru Co

John Thompson 8 Aug 24, 2022