Redis stands for Remote Dictionary Server. It is an open source NoSQL database. It doesn’t have any tables, rows and columns. Also, it doesn’t allow statements like select statement, insert statements, update statements etc.
It stores objects using key/value and basically used to cache and quick-response in an application to speed or increase performance.
Various ways of Redis
In-Memory Database(IMDS) enables minimal response times. It provides responses in microsecond of times. It is the good choice for the application if an application handles the large numbers of traffic.
Advantages:
The cache provides data quickly with high latency to increase the data retrieval performance. Redis is the good choice for caching API calls, session states, and database queries etc.
Advantages:
When a request comes, the code of logic checks in the Redis cache for the desired data. If appropriate data is available in the redis cache, logic simply returns the data from redis cache.
If the requested data is not available/found in the redis cache, the logic falls back to the database or original data source to retrieve the required information to return required data. Subsequently, the fetched data is stored in the Redis cache.
Below dependency is required in spring boot application.
<
dependency> <
groupId> org.springframework.boot <
/groupId> <
artifactId> spring-boot-starter-data-redis <
/artifactId> <
version> 3.2.5 <
/version> <
/dependency>
<
dependency> <
groupId> org.apache.kafka <
/groupId> <
artifactId> kafka-clients <
/artifactId> <
version> 0.9.0.0 <
/version> <
/dependency>
import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.ConsumerRecords; import org.apache.kafka.clients.consumer.KafkaConsumer; import org.apache.kafka.common.serialization.StringDeserializer; import java.time.Duration; import java.util.Arrays; import java.util.Properties; public class KafkaConsumerExample { static String TOPIC_NAME= "first-topic"; public static void main(String args[]) { try { Properties properties = new Properties(); properties.setProperty( ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092" ); properties.setProperty( ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName() ); properties.setProperty( ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName() ); properties.setProperty( ConsumerConfig.GROUP_ID_CONFIG, "my_consumer_group" ); KafkaConsumer<
String, String
> cons = new KafkaConsumer<>(properties); //Subscribe to the topic to consume messages/events. cons.subscribe(Arrays.asList(TOPIC_NAME)); Duration duration = Duration.ofSeconds(1); System.out.println("*Started Receiving Messages*"); while (true) { ConsumerRecords<
String, String
> records = cons.poll(duration.toMillis()); for (ConsumerRecord<
String, String
> record : records) { System.out.println("Received event: " + record.value()); } } }catch(Exception e){ e.printStackTrace(); } } } Output: *Started Receiving Messages* Received event: I am Good! Received event: What about You? Received event: Hope you are also well?
zookeeper-server-stop.bat