import de.juplo.kafka.chat.backend.implementation.kafka.messages.data.EventChatMessageReceivedTo;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
-import org.apache.kafka.clients.consumer.Consumer;
-import org.apache.kafka.clients.consumer.ConsumerRebalanceListener;
-import org.apache.kafka.clients.consumer.ConsumerRecord;
-import org.apache.kafka.clients.consumer.ConsumerRecords;
+import org.apache.kafka.clients.consumer.*;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.TopicPartition;
private final Consumer<String, AbstractMessageTo> consumer;
private final ZoneId zoneId;
private final int numShards;
+ private final Duration pollingInterval;
private final int bufferSize;
private final Clock clock;
private final boolean[] isShardOwned;
Consumer<String, AbstractMessageTo> dataChannelConsumer,
ZoneId zoneId,
int numShards,
+ Duration pollingInterval,
int bufferSize,
Clock clock,
InfoChannel infoChannel,
this.producer = producer;
this.zoneId = zoneId;
this.numShards = numShards;
+ this.pollingInterval = pollingInterval;
this.bufferSize = bufferSize;
this.clock = clock;
this.isShardOwned = new boolean[numShards];
"Could not publish instance {} as owner of shard {}: {}",
instanceId,
partition,
- throwable))
+ throwable.toString()))
+ .onErrorComplete()
.block();
});
{
int partition = topicPartition.partition();
isShardOwned[partition] = false;
+ nextOffset[partition] = consumer.position(topicPartition);
log.info("Partition revoked: {} - next={}", partition, nextOffset[partition]);
infoChannel.sendShardRevokedEvent(partition);
});
{
try
{
- ConsumerRecords<String, AbstractMessageTo> records = consumer.poll(Duration.ofMinutes(1));
+ ConsumerRecords<String, AbstractMessageTo> records = consumer.poll(pollingInterval);
log.info("Fetched {} messages", records.count());
if (loadInProgress)
KafkaChatMessageService service = new KafkaChatMessageService(this, chatRoomId);
return new ChatRoomData(clock, service, bufferSize);
}
+
+ ConsumerGroupMetadata getConsumerGroupMetadata()
+ {
+ return consumer.groupMetadata();
+ }
}