βΆοΈ Stable and Unstable Sort:-
β’ Stable and Unstable sort comes into play when we have duplicate elements.
1. Unstable Sort :- If a Sort is unstable , then that means the relative ordering of the duplicate items will not be preserved. In Unstable sort the position of two or more elements get flipped, their relative ordering is not being preserved.
2. Stable Sort :- If the relative Ordering of the duplicate items is preserved after sorting then that sorting technique is called Stable Sort.
β’ A Stable sort is preferable to an unstable sort.
βΆοΈ Any Sorting in which we swap and not consider equality is Stable.
β’ Bubble Sort is a Stable Algorithm.
β’ Stable and Unstable sort comes into play when we have duplicate elements.
1. Unstable Sort :- If a Sort is unstable , then that means the relative ordering of the duplicate items will not be preserved. In Unstable sort the position of two or more elements get flipped, their relative ordering is not being preserved.
2. Stable Sort :- If the relative Ordering of the duplicate items is preserved after sorting then that sorting technique is called Stable Sort.
β’ A Stable sort is preferable to an unstable sort.
βΆοΈ Any Sorting in which we swap and not consider equality is Stable.
β’ Bubble Sort is a Stable Algorithm.
New Doc 2018-09-26 12.49.52.pdf
2 MB
Share New Doc 2018-09-26 12.49.52.pdf
Fractal Models and Projections_CG.pdf
3.9 MB
Share Fractal Models and Projections_CG.pdf
SPLINE_CG.pdf
2.9 MB
Share SPLINE_CG.pdf
C,C++,JAVA,SPRING,R,PYTHON,SQL Developer, Javascript MOTIVATION and programming & coding channel.π»π»
Photo
βΆοΈ Dependency for implementing Circuit Breaker using Resilience4j :
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
</dependency>
C,C++,JAVA,SPRING,R,PYTHON,SQL Developer, Javascript MOTIVATION and programming & coding channel.π»π»
βΆοΈ Dependency for implementing Circuit Breaker using Resilience4j : <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId> </dependency>
βΆοΈ Properties needed to define in application.properties file to implement circuit breaker using Resilience4j :
#Resilinece4j Properties
resilience4j.circuitbreaker.configs.default.registerHealthIndicator=true
resilience4j.circuitbreaker.configs.default.slidingWindowType=COUNT_BASED
resilience4j.circuitbreaker.configs.default.slidingWindowSize=10
resilience4j.circuitbreaker.configs.default.failureRateThreshold=50
resilience4j.circuitbreaker.configs.default.waitDurationInOpenState=5s
resilience4j.circuitbreaker.configs.default.permittedNumberOfCallsInHalfOpenState=3
resilience4j.circuitbreaker.configs.default.automaticTransitionFromOpenToHalfOpenEnabled=true
resilience4j.circuitbreaker.configs.default.minimum-number-of-calls=5
#Resilience4J Timeout Properties
resilience4j.timelimiter.configs.default.timeout-duration=3s
#Resilience4J Retry Properties
resilience4j.retry.configs.default.max-attempts=3
resilience4j.retry.configs.default.wait-duration=2s
#Resilinece4j Properties
resilience4j.circuitbreaker.configs.default.registerHealthIndicator=true
resilience4j.circuitbreaker.configs.default.slidingWindowType=COUNT_BASED
resilience4j.circuitbreaker.configs.default.slidingWindowSize=10
resilience4j.circuitbreaker.configs.default.failureRateThreshold=50
resilience4j.circuitbreaker.configs.default.waitDurationInOpenState=5s
resilience4j.circuitbreaker.configs.default.permittedNumberOfCallsInHalfOpenState=3
resilience4j.circuitbreaker.configs.default.automaticTransitionFromOpenToHalfOpenEnabled=true
resilience4j.circuitbreaker.configs.default.minimum-number-of-calls=5
#Resilience4J Timeout Properties
resilience4j.timelimiter.configs.default.timeout-duration=3s
#Resilience4J Retry Properties
resilience4j.retry.configs.default.max-attempts=3
resilience4j.retry.configs.default.wait-duration=2s
C,C++,JAVA,SPRING,R,PYTHON,SQL Developer, Javascript MOTIVATION and programming & coding channel.π»π»
Photo
βΆοΈ What is circuit breaker and why to use it :
In our microservices application sometimes if one service stops working then it is waste of resources and time to call the entire services and get us back that a service is not working it is completely a waste of time and resources, so to avoid that we apply circuit breaker at the API gateway level so that we don't have to waste resources and time as api gateway is the entry point of any microservices application,so that at just entry level it shows that our service is not working,so to implement the functionality like that,to save resources and time,we need and use circuit breaker.
In our microservices application sometimes if one service stops working then it is waste of resources and time to call the entire services and get us back that a service is not working it is completely a waste of time and resources, so to avoid that we apply circuit breaker at the API gateway level so that we don't have to waste resources and time as api gateway is the entry point of any microservices application,so that at just entry level it shows that our service is not working,so to implement the functionality like that,to save resources and time,we need and use circuit breaker.
C,C++,JAVA,SPRING,R,PYTHON,SQL Developer, Javascript MOTIVATION and programming & coding channel.π»π»
βΆοΈ What is circuit breaker and why to use it : In our microservices application sometimes if one service stops working then it is waste of resources and time to call the entire services and get us back that a service is not working it is completely a wasteβ¦
βΆοΈ There are 3 states of circuit breaker :
1. Open
2. Closed
3. Half Open
1. Open
2. Closed
3. Half Open
C,C++,JAVA,SPRING,R,PYTHON,SQL Developer, Javascript MOTIVATION and programming & coding channel.π»π»
βΆοΈ There are 3 states of circuit breaker : 1. Open 2. Closed 3. Half Open
#How to add kafka in our project as a container through docker:
1.a) Add this property in docker-compose.yml file located in your root folder of your project or particular module :
zookeeper:
image: confluentinc/cp-zookeeper:7.5.0
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
broker:
image: confluentinc/cp-kafka:7.5.0
container_name: broker
ports:
- "9092:9092"
- "29092:29092"
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
schema-registry:
image: confluentinc/cp-schema-registry:7.5.0
hostname: schema-registry
container_name: schema-registry
depends_on:
- broker
ports:
- "8085:8081"
environment:
SCHEMA_REGISTRY_HOST_NAME: schema-registry
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: 'broker:29092'
SCHEMA_REGISTRY_LISTENERS: http://schema-registry:8081
kafka-ui:
container_name: kafka-ui
image: provectuslabs/kafka-ui:latest
ports:
- "8086:8080"
depends_on:
- broker
environment:
KAFKA_CLUSTERS_NAME: local
KAFKA_CLUSTERS_BOOTSTRAPSERVERS: broker:29092
#KAFKA_CLUSTERS_SCHEMAREGISTRY: http://schema-registry:8081
DYNAMIC_CONFIG_ENABLED: 'true'
b) After that open terminal and go to where ur docker-compose.yml file is located and then run this command in terminal :
docker compose up -d
This will create a container of kafka in our project which we can use easily.
1.a) Add this property in docker-compose.yml file located in your root folder of your project or particular module :
zookeeper:
image: confluentinc/cp-zookeeper:7.5.0
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
broker:
image: confluentinc/cp-kafka:7.5.0
container_name: broker
ports:
- "9092:9092"
- "29092:29092"
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
schema-registry:
image: confluentinc/cp-schema-registry:7.5.0
hostname: schema-registry
container_name: schema-registry
depends_on:
- broker
ports:
- "8085:8081"
environment:
SCHEMA_REGISTRY_HOST_NAME: schema-registry
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: 'broker:29092'
SCHEMA_REGISTRY_LISTENERS: http://schema-registry:8081
kafka-ui:
container_name: kafka-ui
image: provectuslabs/kafka-ui:latest
ports:
- "8086:8080"
depends_on:
- broker
environment:
KAFKA_CLUSTERS_NAME: local
KAFKA_CLUSTERS_BOOTSTRAPSERVERS: broker:29092
#KAFKA_CLUSTERS_SCHEMAREGISTRY: http://schema-registry:8081
DYNAMIC_CONFIG_ENABLED: 'true'
b) After that open terminal and go to where ur docker-compose.yml file is located and then run this command in terminal :
docker compose up -d
This will create a container of kafka in our project which we can use easily.
C,C++,JAVA,SPRING,R,PYTHON,SQL Developer, Javascript MOTIVATION and programming & coding channel.π»π»
#How to add kafka in our project as a container through docker: 1.a) Add this property in docker-compose.yml file located in your root folder of your project or particular module : zookeeper: image: confluentinc/cp-zookeeper:7.5.0 hostname: zookeeperβ¦
2. Add kafka dependency as a dependency in your spring project :
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
C,C++,JAVA,SPRING,R,PYTHON,SQL Developer, Javascript MOTIVATION and programming & coding channel.π»π»
2. Add kafka dependency as a dependency in your spring project : <dependency> <groupId>org.springframework.kafka</groupId> <artifactId>spring-kafka</artifactId> </dependency>
3. Add these properties in application.properties file of your request producer service module :
#Kafka Properties.
spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.template.default-topic=order-placed(topic_written_in_service_layer)
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer
#Kafka Properties.
spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.template.default-topic=order-placed(topic_written_in_service_layer)
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer
C,C++,JAVA,SPRING,R,PYTHON,SQL Developer, Javascript MOTIVATION and programming & coding channel.π»π»
3. Add these properties in application.properties file of your request producer service module : #Kafka Properties. spring.kafka.bootstrap-servers=localhost:9092 spring.kafka.template.default-topic=order-placed(topic_written_in_service_layer) spring.kafka.producer.keyβ¦
4. Dependencies to enable avro and schema-registry in our project(In Request Producer module/part of project):-
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-avro-serializer</artifactId>
<version>7.6.0</version>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-schema-registry-client</artifactId>
<version>7.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.11.3</version>
</dependency>
Also add plugin as follows :
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<executions>
<execution>
<id>schemas</id>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/resources/avro</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-avro-serializer</artifactId>
<version>7.6.0</version>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-schema-registry-client</artifactId>
<version>7.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.11.3</version>
</dependency>
Also add plugin as follows :
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<executions>
<execution>
<id>schemas</id>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/resources/avro</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>