Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
more events(delete and update) added to the order service #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
more events(delete and update) added to the order service #23
Changes from 1 commit
6b2c5b2c655e4dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
EcommerceAPI
This is an Ecommerce microservices project. In microservices architecture, each service is a separate entity and can be developed, deployed, scaled and maintained independently. This project is a simple example of an Ecommerce microservices project. It consists of the following services:
The choice of communication between services will be RESTful API. The options are:
Asynchronous and non-blocking calls are calls recommended for microservices architecture.
Asynchronous calls: These allow a program to initiate a task and move on to other tasks before the initial task is completed. This helps in utilizing resources more efficiently and improving the overall performance of the application.
Non-blocking calls: These ensure that the program does not wait for the task to complete before moving on to the next task. This is particularly useful in I/O operations where waiting for a response can be time-consuming.
In the context of microservices, asynchronous and non-blocking calls are recommended because they help in handling multiple service requests concurrently without blocking the execution of other tasks, leading to better scalability and performance
Eureka Server (Service Discovery: Used to register and discover services).
IMPORTANT NOTE: The project will bw implemented using the web client. When microservices need to call each other dynamically, they register with Eureka server and use Eureka client with for service discovery.
API Gateway: This is a single entry point for all the services. It is a reverse proxy that routes requests to the appropriate service.
Steps:
TODO: Switch from Spring Data JPA to Spring Data R2DBC by updating your pom.xml org.springframework.boot spring-boot-starter-data-r2dbc io.r2dbc r2dbc-postgresql
maven command for cleaning and building the project: mvn clean install -DskipTests To highlight text in the editor: File → Settings → Editor → TODO→ Add a new pattern and choose a color.
POTENTIAL MEMORY LEAKS:
API DOCUMENTATION:
STEPS TO ADD SPRINGDOC-OPENAPI-UI: - Add the following dependency in the pom.xml file for springdoc-openapi-ui. - change path in the application.yml: e.g., http://localhost:port/swagger-ui.html - Add the @OpenAPIDefinition annotation in the main class of the services. - Configure the application.yml file with the springdoc-openapi-ui details. - Expose an API to get the API documentation. - Access the API documentation at http://localhost:port/swagger-ui.html
TESTING KAFAKA:
PRODUCER: docker run -it --rm --network common-utils_microservices-network
confluentinc/cp-kafka:latestkafka-console-producer --bootstrap-server kafka:9092 --topic test-topicAfter running the above command, you can type messages in the console and press Enter to send them to the Kafka topic. Press Ctrl+C to exit the producer.
CONSUMER: docker run --rm --network common-utils_microservices-network
confluentinc/cp-kafka:latestkafka-console-consumer --bootstrap-server kafka:9092 --topic ecommerce-topic --from-beginning --max-messages 5This will show the first 5 messages in test-topic. After running the above command, you will see the messages sent to the Kafka topic in the console. Press Ctrl+C to exit the consumer.
#OR
-i confluentinc/cp-kafka:latestkafka-console-producer --bootstrap-server kafka:9092 --topic test-topicChecking specific kafka broker versions:
Rebuilding docker image for a specific service with no cache:
docker build --no-cache
docker-compose up -d To run all images in a docker compose file in detached mode:
docker compose up -d --build To stop all images in a docker compose file:
docker compose down To stop a specific service in a docker compose file:
docker compose stop To start a specific service in a docker compose file:
docker compose start To view logs of a specific service in a docker compose file:
docker compose logs -f
In case, service is not behaving same in docker as in local: *mvn clean install -DskipTests *then rebuild the docker image for the service with no cache: *docker build --no-cache *docker compose down -v: to remove all volumes
*to remove specific service volume: *docker volume rm common-utils_-data *docker-compose up -d
summary: Remove all containers, volumes, and images (use with caution as this will delete all your data): *docker rm -f$(docker ps -aq) && docker volume rm $ (docker volume ls -q) && docker rmi -f $(docker images -q) docker rm -f $ (docker ps -aq)
docker ps -aq → lists all container IDs (running + stopped).
docker rm -f ... → force-removes all those containers.
docker volume rm $(docker volume ls -q)
docker volume ls -q → lists all volume names/IDs.
docker volume rm ... → deletes all volumes.
docker rmi -f $(docker images -q)
docker images -q → lists all image IDs.
docker rmi -f ... → force-removes all images.
&& chaining
Ensures that the next command only runs if the previous one succeeds.
SETTING UP A CUSTOM CONTAINER FOR KAFKA FOR TESTING PURPOSES: @Container public static final GenericContainer<?> kafka = new GenericContainer<>("confluentinc/cp-kafka:7.8.0") .withExposedPorts(9092, 29092) .withEnv("KAFKA_BROKER_ID", "1") .withEnv("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "1") .withEnv("KAFKA_LISTENERS", "PLAINTEXT://0.0.0.0:9092") .withEnv("KAFKA_ADVERTISED_LISTENERS", "PLAINTEXT://localhost:9092") .waitingFor(Wait.forLogMessage(".started.\n", 1));
Firebase Cloud Messaging (FCM) for sending notifications:
Reasons why .env content gets loaded locally when services run *When there is spring boot dev tool dependency in the pom.xml file. *IDE Automatic .env loading: *Some IDEs (like IntelliJ IDEA) automatically load environment variables from a .env file when running a Spring Boot application.This feature is often enabled by default to facilitate development and testing.
Command to show dependency, for example: com.vaadin.external.google:android-json
* mvn dependency:tree -Dincludes="com.vaadin.external.google:android-json"
How to convert secret json file to base64 encoded string: *This is useful when you want to store the secret in an environment variable or a secret manager. *You can use the following command to convert the json file to base64 encoded string: *Navigate to the directory where the serviceAccountKey.json file is located. *Run the following command to convert the json file to base64 encoded string: * Linux/Mac: cat path/to/your/serviceAccountKey.json | base64 * Windows (PowerShell): [Convert]::ToBase64String([System.IO.File]::ReadAllBytes("path\to\your\serviceAccountKey.json")) * Set-Content -Path "path\to\your\encodedFile.txt" -Value $base64String * Open the encodedFile.txt to get the base64 encoded string. *Check other details on how to use the secret in Github Actions here: ONE NOTE
Useful Git command: * delete branch: git branch -d
Uh oh!
There was an error while loading. Please reload this page.