import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
+import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.IntegerDeserializer;
import org.apache.kafka.common.serialization.IntegerSerializer;
import org.apache.kafka.common.serialization.StringDeserializer;
@Bean
Producer<Integer, ChatRoomTo> chatRoomChannelProducer(
- Properties producerProperties,
+ Properties defaultProducerProperties,
IntegerSerializer integerSerializer,
JsonSerializer<ChatRoomTo> chatRoomSerializer)
{
return new KafkaProducer<>(
- producerProperties,
+ defaultProducerProperties,
integerSerializer,
chatRoomSerializer);
}
@Bean
Consumer<Integer, ChatRoomTo> chatRoomChannelConsumer(
- Properties producerProperties,
+ Properties defaultConsumerProperties,
IntegerDeserializer integerDeserializer,
JsonDeserializer<ChatRoomTo> chatRoomDeserializer)
{
+ Properties properties = new Properties(defaultConsumerProperties);
+ properties.setProperty(
+ ConsumerConfig.GROUP_ID_CONFIG,
+ "chat_room_channel");
return new KafkaConsumer<>(
- producerProperties,
+ properties,
integerDeserializer,
chatRoomDeserializer);
}
@Bean
Producer<String, MessageTo> chatMessageChannelProducer(
- Properties producerProperties,
+ Properties defaultProducerProperties,
StringSerializer stringSerializer,
JsonSerializer<MessageTo> messageSerializer)
{
return new KafkaProducer<>(
- producerProperties,
+ defaultProducerProperties,
stringSerializer,
messageSerializer);
}
@Bean
Consumer<String, MessageTo> chatMessageChannelConsumer(
- Properties producerProperties,
+ Properties defaultConsumerProperties,
StringDeserializer stringDeserializer,
JsonDeserializer<MessageTo> messageDeserializer)
{
+ Properties properties = new Properties(defaultConsumerProperties);
+ properties.setProperty(
+ ConsumerConfig.GROUP_ID_CONFIG,
+ "chat_message_channel");
return new KafkaConsumer<>(
- producerProperties,
+ properties,
stringDeserializer,
messageDeserializer);
}
}
@Bean
- Properties producerProperties(ChatBackendProperties chatBackendProperties)
+ Properties defaultProducerProperties(ChatBackendProperties chatBackendProperties)
{
Properties properties = new Properties();
+ properties.setProperty(
+ ProducerConfig.CLIENT_ID_CONFIG,
+ chatBackendProperties.getKafka().getClientId());
+ properties.setProperty(
+ ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,
+ chatBackendProperties.getKafka().getBootstrapServers());
return properties;
}
@Bean
- Properties consumerProperties(ChatBackendProperties chatBackendProperties)
+ Properties defaultConsumerProperties(ChatBackendProperties chatBackendProperties)
{
Properties properties = new Properties();
+ properties.setProperty(
+ ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,
+ chatBackendProperties.getKafka().getBootstrapServers());
+ properties.setProperty(
+ ConsumerConfig.CLIENT_ID_CONFIG,
+ chatBackendProperties.getKafka().getClientId());
+ properties.setProperty(
+ ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG,
+ "false");
+ properties.setProperty(
+ ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
+ "earliest");
return properties;
}