Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class PulsarPullConsumerImpl<T> implements PulsarPullConsumer<T> {
private final Map<String, Consumer<T>> consumerMap;
private final OffsetToMessageIdCache offsetToMessageIdCache;
private final ReaderCache<T> readerCache;
private final PulsarAdmin pulsarAdmin;
private final Supplier<PulsarAdmin> pulsarAdminSupplier;
private final Supplier<PulsarClient> pulsarClientSupplier;
private final ConsumerBuilder<T> consumerBuilder;

Expand All @@ -74,18 +74,19 @@ public PulsarPullConsumerImpl(
String brokerCluster,
Schema<T> schema,
Supplier<PulsarClient> clientSupplier,
PulsarAdmin admin,
Supplier<PulsarAdmin> adminSupplier,
ConsumerBuilder<T> consumerBuilder) {
this.topic = Objects.requireNonNull(topic, "Topic must not be null");
this.subscription = Objects.requireNonNull(subscription, "Subscription must not be null");
this.brokerCluster = Objects.requireNonNull(brokerCluster, "Broker cluster must not be null");
this.schema = Objects.requireNonNull(schema, "Schema must not be null");
this.pulsarClientSupplier =
Objects.requireNonNull(clientSupplier, "PulsarClient must not be null");
this.pulsarAdmin = Objects.requireNonNull(admin, "PulsarAdmin must not be null");
this.pulsarAdminSupplier =
Objects.requireNonNull(adminSupplier, "PulsarAdmin must not be null");
this.consumerMap = new ConcurrentHashMap<>();
this.offsetToMessageIdCache =
OffsetToMessageIdCacheProvider.getOrCreateCache(admin, brokerCluster);
OffsetToMessageIdCacheProvider.getOrCreateCache(getPulsarAdmin(), brokerCluster);
this.readerCache =
ReaderCacheProvider.getOrCreateReaderCache(
this.subscription, brokerCluster, schema, clientSupplier.get(), offsetToMessageIdCache);
Expand All @@ -105,7 +106,8 @@ public void start() throws PulsarClientException {
}

private void initializePartitions() throws PulsarAdminException, PulsarClientException {
PartitionedTopicMetadata metadata = pulsarAdmin.topics().getPartitionedTopicMetadata(topic);
PartitionedTopicMetadata metadata =
getPulsarAdmin().topics().getPartitionedTopicMetadata(topic);
this.partitionCount = metadata.partitions;

if (partitionCount == 0) {
Expand All @@ -132,6 +134,12 @@ private PulsarClient getPulsarClient() {
"PulsarClient supplier returned null. Ensure PulsarClient is properly initialized.");
}

private PulsarAdmin getPulsarAdmin() {
return Objects.requireNonNull(
pulsarAdminSupplier.get(),
"PulsarAdmin supplier returned null. Ensure PulsarAdmin is properly initialized.");
}

@Override
public PullResponse<T> pull(PullRequest request) {
validatePullParameters(request.getMaxMessages(), request.getMaxBytes());
Expand Down Expand Up @@ -231,14 +239,15 @@ public void ack(long offset, int partition, CommandAck.AckType ackType)
@Override
public long searchOffset(int partition, long timestamp) throws PulsarAdminException {
String partitionTopic = buildPartitionTopic(topic, partition);
return PulsarAdminUtils.searchOffset(partitionTopic, timestamp, brokerCluster, pulsarAdmin);
return PulsarAdminUtils.searchOffset(
partitionTopic, timestamp, brokerCluster, getPulsarAdmin());
}

@Override
public ConsumeStats getConsumeStats(int partition) throws PulsarAdminException {
String partitionTopic = buildPartitionTopic(topic, partition);
return PulsarAdminUtils.getConsumeStats(
partitionTopic, partition, subscription, brokerCluster, pulsarAdmin);
partitionTopic, partition, subscription, brokerCluster, getPulsarAdmin());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void testPullConsumer(String topic, int partitionIndex) throws Exception
brokerCluster,
Schema.BYTES,
() -> pulsarClient,
pulsarAdmin,
() -> pulsarAdmin,
null);
pullConsumer.start();

Expand Down Expand Up @@ -177,7 +177,7 @@ public void testSearchOffset(String topic, int partitionIndex) throws Exception
brokerCluster,
Schema.BYTES,
() -> pulsarClient,
pulsarAdmin,
() -> pulsarAdmin,
null);
pullConsumer.start();

Expand Down Expand Up @@ -218,7 +218,7 @@ public void testGetConsumeStats() {
brokerCluster,
Schema.BYTES,
() -> pulsarClient,
pulsarAdmin,
() -> pulsarAdmin,
null);
pullConsumer.start();

Expand Down
Loading