-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from manjeetvk/master
Added code that parallelize offset request per broker to improve performance
- Loading branch information
Showing
4 changed files
with
274 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
ConsumerGroupLag/src/main/java/com/wushujames/kafka/KafkaApiRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.wushujames.kafka; | ||
|
||
import org.apache.kafka.clients.ClientResponse; | ||
import org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient; | ||
import org.apache.kafka.clients.consumer.internals.RequestFuture; | ||
import org.apache.kafka.common.Node; | ||
import org.apache.kafka.common.requests.AbstractRequest; | ||
import org.apache.kafka.common.requests.AbstractResponse; | ||
|
||
public class KafkaApiRequest { | ||
|
||
final private ConsumerNetworkClient networkClient; | ||
private RequestFuture<ClientResponse> clientResponse = null; | ||
|
||
KafkaApiRequest(final ConsumerNetworkClient networkClient){ | ||
this.networkClient = networkClient; | ||
} | ||
|
||
public void sendApiRequest(final Node node, final AbstractRequest.Builder<?> requestBuilder){ | ||
this.clientResponse = this.networkClient.send(node, requestBuilder); | ||
} | ||
|
||
public AbstractResponse getLastApiResponse(final long waitTimeMsBetweenCheckingResponse){ | ||
|
||
while(!this.clientResponse.isDone()){ | ||
try { | ||
Thread.sleep(waitTimeMsBetweenCheckingResponse); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return this.clientResponse.value().responseBody(); | ||
} | ||
} | ||
|
7 changes: 7 additions & 0 deletions
7
ConsumerGroupLag/src/main/java/com/wushujames/kafka/OffsetFetchException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.wushujames.kafka; | ||
|
||
public class OffsetFetchException extends Exception { | ||
public OffsetFetchException(String message) { | ||
super(message); | ||
} | ||
} |
Oops, something went wrong.