This project is a microservice-based payment system developed using Spring Boot and Spring Cloud. It aims to demonstrate modern cloud-native application patterns such as service discovery, an API gateway, and asynchronous communication in distributed systems.
The project consists of four main services, each responsible for a specific function:
This is where all microservices in the system register and discover each other. Other services register with Eureka to announce their network location (IP address and port), allowing them to communicate with each other dynamically. In short, it acts as the system's phone book.
It is the single point of entry for all client requests. It routes incoming requests to the appropriate microservice. It also manages cross-cutting concerns like authentication. When a user logs in, it generates a JWT (JSON Web Token) and secures requests to other services with this token.
Manages all responsibilities related to user operations. It handles tasks such as creating new user registrations and verifying the credentials of existing users. When a new user is created, it notifies other services (e.g., account-service) via RabbitMQ.
Manages all operations related to user accounts, balances, and financial transactions. When it receives a notification from RabbitMQ that a new user has been created, it automatically opens an account for that user. It handles operations like deposits, withdrawals, and balance inquiries.
You can follow the steps below to run the project on your local machine:
-
Start the Eureka Server: First, start the
eureka-serverapplication. It needs to be running before all other services can connect to it. -
Start the Other Services: Next, start the
user-service,account-service, andgateway-serviceapplications in any order. -
Access: Once all services have started successfully, the system will be accessible through the
gateway-service(by default athttp://localhost:8080).
This project excludes application.yml files from version control using .gitignore. To run the project, you need to create an application.yml file in the src/main/resources directory of each service with the content specified below.
File Path: eureka-server/src/main/resources/application.yml
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: falseFile Path: gateway-service/src/main/resources/application.yml
Note: The
jwt.secretvalue here must be the same as the value in the other services.
server:
port: 8080
spring:
application:
name: gateway-service
cloud:
gateway:
routes:
- id: user-service-register-route
uri: lb://user-service
predicates:
- Path=/api/auth/register
filters:
- StripPrefix=2
- id: account-service-route
uri: lb://account-service
predicates:
- Path=/api/account/**
filters:
- name: AuthenticationFilter
- StripPrefix=1
jwt:
secret: MCZNZmpEWS13Olp4LS5bIypxYmozViRnQ3kvQlovKU0=File Path: user-service/src/main/resources/application.yml
Note: Don't forget to update the
url,username, andpasswordfields underspring.datasourceaccording to your own PostgreSQL database configuration.
spring:
application:
name: user-service
profiles:
active: dev
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
jpa:
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
datasource:
url: jdbc:postgresql://localhost:5433/user_db
username: postgres
password: your_db_password # Enter your own password
driver-class-name: org.postgresql.Driver
server:
port: 8081
rabbitmq:
queue:
user-created: user-created-queue
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
instance:
prefer-ip-address: trueFile Path: account-service/src/main/resources/application.yml
Note: Don't forget to update the
url,username, andpasswordfields underspring.datasourceaccording to your own PostgreSQL database configuration. Thejwt.secretvalue must be the same as in thegateway-service.
spring:
application:
name: account-service
profiles:
active: dev
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
jpa:
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
datasource:
url: jdbc:postgresql://localhost:5433/account_db
username: postgres
password: your_db_password # Enter your own password
driver-class-name: org.postgresql.Driver
jwt:
secret: MCZNZmpEWS13Olp4LS5bIypxYmozViRnQ3kvQlovKU0=
server:
port: 8082
rabbitmq:
queue:
user-created: user-created-queue
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
instance:
preferIpAddress: true