import de.juplo.kafka.chat.backend.ChatBackendProperties;
import de.juplo.kafka.chat.backend.domain.ChatHomeService;
+import de.juplo.kafka.chat.backend.domain.ShardingPublisherStrategy;
+import de.juplo.kafka.chat.backend.implementation.haproxy.HaproxyShardingPublisherStrategy;
import de.juplo.kafka.chat.backend.implementation.kafka.messages.AbstractMessageTo;
import de.juplo.kafka.chat.backend.implementation.kafka.messages.data.EventChatMessageReceivedTo;
import de.juplo.kafka.chat.backend.implementation.kafka.messages.info.EventChatRoomCreated;
import org.springframework.kafka.support.serializer.JsonSerializer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import java.net.InetSocketAddress;
import java.time.Clock;
import java.time.ZoneId;
import java.util.HashMap;
@Bean
ConsumerTaskRunner consumerTaskRunner(
ConsumerTaskExecutor infoChannelConsumerTaskExecutor,
- ConsumerTaskExecutor dataChannelConsumerTaskExecutor)
+ ConsumerTaskExecutor dataChannelConsumerTaskExecutor,
+ InfoChannel infoChannel)
{
return new ConsumerTaskRunner(
infoChannelConsumerTaskExecutor,
- dataChannelConsumerTaskExecutor);
+ dataChannelConsumerTaskExecutor,
+ infoChannel);
}
@Bean
}
@Bean
- ChatHomeService kafkaChatHome(
+ KafkaChatHomeService kafkaChatHome(
ChatBackendProperties properties,
InfoChannel infoChannel,
DataChannel dataChannel)
return new InfoChannel(
properties.getKafka().getInfoChannelTopic(),
producer,
- infoChannelConsumer);
+ infoChannelConsumer,
+ properties.getKafka().getInstanceUri());
}
@Bean
Consumer<String, AbstractMessageTo> dataChannelConsumer,
ZoneId zoneId,
Clock clock,
- InfoChannel infoChannel)
+ InfoChannel infoChannel,
+ ShardingPublisherStrategy shardingPublisherStrategy)
{
return new DataChannel(
+ properties.getInstanceId(),
properties.getKafka().getDataChannelTopic(),
producer,
dataChannelConsumer,
properties.getKafka().getNumPartitions(),
properties.getChatroomBufferSize(),
clock,
- infoChannel);
+ infoChannel,
+ shardingPublisherStrategy);
}
@Bean
return properties;
}
+ @Bean
+ ShardingPublisherStrategy shardingPublisherStrategy(
+ ChatBackendProperties properties)
+ {
+ String[] parts = properties.getKafka().getHaproxyRuntimeApi().split(":");
+ InetSocketAddress haproxyAddress = new InetSocketAddress(parts[0], Integer.valueOf(parts[1]));
+ return new HaproxyShardingPublisherStrategy(
+ haproxyAddress,
+ properties.getKafka().getHaproxyMap(),
+ properties.getInstanceId());
+ }
+
@Bean
ZoneId zoneId()
{