Размер видео: 1280 X 720853 X 480640 X 360
Показать панель управления
Автовоспроизведение
Автоповтор
org.springframework.kafka spring-kafka
1. Install Kafka and Zookeeper2. Create Springboot App1 - Producer3. Create Springboot App2 - Consumer4. Test Kafka Messaging-----------------application.properties for CONSUMER microservicespring.kafka.consumer.bootstrap-servers = localhost:9092spring.kafka.consumer.group-id= group_idspring.kafka.consumer.auto-offset-reset = earliestspring.kafka.consumer.key-deserializer= org.apache.kafka.common.serialization.StringDeserializerspring.kafka.consumer.value-deserializer = org.apache.kafka.common.serialization.StringDeserializer-------------------application.properties for PRODUCER microservicespring.kafka.producer.bootstrap-servers = localhost:9092spring.kafka.producer.key-serializer = org.apache.kafka.common.serialization.StringSerializerspring.kafka.producer.value-serializer = org.apache.kafka.common.serialization.StringSerializer--------------Code Snippet for sending Kafka message: @Autowired private KafkaTemplate kafkaTemplate; public void send() { kafkaTemplate.send("testtopic1", "test msg"); }--------------Code Snippet for consuming Kafka message: @KafkaListener(topics = "testtopic1", groupId = "*") public void listenGroupFoo(String message) { System.out.println("Received Message in group foo: " + message); } ------------------kafka-install.yml to install Kafka:version: '3'services: zookeeper: image: wurstmeister/zookeeper container_name: zookeeper ports: - "2181:2181" kafka: image: wurstmeister/kafka container_name: kafka ports: - "9092:9092" environment: KAFKA_ADVERTISED_HOST_NAME: localhost KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
org.springframework.kafka
spring-kafka
1. Install Kafka and Zookeeper
2. Create Springboot App1 - Producer
3. Create Springboot App2 - Consumer
4. Test Kafka Messaging
-----------------
application.properties for CONSUMER microservice
spring.kafka.consumer.bootstrap-servers = localhost:9092
spring.kafka.consumer.group-id= group_id
spring.kafka.consumer.auto-offset-reset = earliest
spring.kafka.consumer.key-deserializer= org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer = org.apache.kafka.common.serialization.StringDeserializer
-------------------
application.properties for PRODUCER microservice
spring.kafka.producer.bootstrap-servers = localhost:9092
spring.kafka.producer.key-serializer = org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer = org.apache.kafka.common.serialization.StringSerializer
--------------
Code Snippet for sending Kafka message:
@Autowired
private KafkaTemplate kafkaTemplate;
public void send() {
kafkaTemplate.send("testtopic1", "test msg");
}
--------------
Code Snippet for consuming Kafka message:
@KafkaListener(topics = "testtopic1", groupId = "*")
public void listenGroupFoo(String message) {
System.out.println("Received Message in group foo: " + message);
}
------------------
kafka-install.yml to install Kafka:
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
container_name: zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
container_name: kafka
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: localhost
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181