Kafka 조건부 활성화 설정
This commit is contained in:
parent
887b46ab46
commit
43e23eb7aa
@ -3,6 +3,7 @@ package com.kt.event.analytics.config;
|
|||||||
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
||||||
import org.apache.kafka.common.serialization.StringDeserializer;
|
import org.apache.kafka.common.serialization.StringDeserializer;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
|
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
|
||||||
@ -16,6 +17,7 @@ import java.util.Map;
|
|||||||
* Kafka Consumer 설정
|
* Kafka Consumer 설정
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@ConditionalOnProperty(name = "spring.kafka.enabled", havingValue = "true", matchIfMissing = true)
|
||||||
public class KafkaConsumerConfig {
|
public class KafkaConsumerConfig {
|
||||||
|
|
||||||
@Value("${spring.kafka.bootstrap-servers}")
|
@Value("${spring.kafka.bootstrap-servers}")
|
||||||
@ -41,6 +43,8 @@ public class KafkaConsumerConfig {
|
|||||||
ConcurrentKafkaListenerContainerFactory<String, String> factory =
|
ConcurrentKafkaListenerContainerFactory<String, String> factory =
|
||||||
new ConcurrentKafkaListenerContainerFactory<>();
|
new ConcurrentKafkaListenerContainerFactory<>();
|
||||||
factory.setConsumerFactory(consumerFactory());
|
factory.setConsumerFactory(consumerFactory());
|
||||||
|
// Kafka가 없어도 서비스가 시작되도록 자동 시작 비활성화
|
||||||
|
factory.setAutoStartup(false);
|
||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import com.kt.event.analytics.repository.ChannelStatsRepository;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.kafka.annotation.KafkaListener;
|
import org.springframework.kafka.annotation.KafkaListener;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ import org.springframework.stereotype.Component;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
|
@ConditionalOnProperty(name = "spring.kafka.enabled", havingValue = "true", matchIfMissing = false)
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class DistributionCompletedConsumer {
|
public class DistributionCompletedConsumer {
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import com.kt.event.analytics.repository.EventStatsRepository;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.kafka.annotation.KafkaListener;
|
import org.springframework.kafka.annotation.KafkaListener;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ import org.springframework.stereotype.Component;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
|
@ConditionalOnProperty(name = "spring.kafka.enabled", havingValue = "true", matchIfMissing = false)
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class EventCreatedConsumer {
|
public class EventCreatedConsumer {
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import com.kt.event.analytics.repository.EventStatsRepository;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.kafka.annotation.KafkaListener;
|
import org.springframework.kafka.annotation.KafkaListener;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ import org.springframework.stereotype.Component;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
|
@ConditionalOnProperty(name = "spring.kafka.enabled", havingValue = "true", matchIfMissing = false)
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ParticipantRegisteredConsumer {
|
public class ParticipantRegisteredConsumer {
|
||||||
|
|
||||||
|
|||||||
@ -43,13 +43,18 @@ spring:
|
|||||||
|
|
||||||
# Kafka
|
# Kafka
|
||||||
kafka:
|
kafka:
|
||||||
bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS:localhost:9092}
|
enabled: ${KAFKA_ENABLED:false}
|
||||||
|
bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS:4.230.50.63:9092}
|
||||||
consumer:
|
consumer:
|
||||||
group-id: analytics-service
|
group-id: ${KAFKA_CONSUMER_GROUP_ID:analytics-service}
|
||||||
auto-offset-reset: earliest
|
auto-offset-reset: earliest
|
||||||
enable-auto-commit: true
|
enable-auto-commit: true
|
||||||
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
|
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
|
||||||
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
|
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
|
||||||
|
properties:
|
||||||
|
connections.max.idle.ms: 10000
|
||||||
|
request.timeout.ms: 5000
|
||||||
|
session.timeout.ms: 10000
|
||||||
|
|
||||||
# Server
|
# Server
|
||||||
server:
|
server:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user