-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Kafka consumer groups #262
Changes from 68 commits
e49a458
1dea9a5
4209230
8f9ae54
872762e
860a780
b8c4a5a
a955eee
7107968
6f8e5fb
2e67dd0
ad7444d
919a0d4
306543b
c1ce5a3
b8dd0bb
0f542fe
175bf8b
ed3e339
802cff7
5e6a742
df8da88
9729be6
30ba518
af4eaa9
d5beb2c
2471375
50690a9
e6571fa
ce207fe
3e32394
32a0a3c
c64f9cf
bf7826e
999fd4d
18c1331
816e0ac
275d7f3
bb94a7d
ebf2050
08315ea
d71dff2
95afdbe
975a846
f9494b5
4f2a1f5
89a7988
04eed7c
635eb92
542940c
8ceb90a
d0abbe4
a986141
e1c986f
42ded2f
dfbd251
e7f7912
58e5bd5
515047a
c1c0e51
e9f2d44
9df825a
6f2a664
5b431c4
8c435cb
2a52135
2aeceec
8e80f42
85d03ce
9add48f
23ffbfe
344dee5
002d4c1
8c85e39
bb07f7d
ef5090b
eddfbea
ae6eef7
a71ace4
d87d676
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import java.math.BigInteger; | ||
import java.nio.file.Path; | ||
import java.security.SecureRandom; | ||
import java.util.UUID; | ||
import java.util.function.Supplier; | ||
|
||
import org.agrona.LangUtil; | ||
|
@@ -63,6 +64,10 @@ public class KafkaConfiguration extends Configuration | |
public static final IntPropertyDef KAFKA_CACHE_CLIENT_TRAILERS_SIZE_MAX; | ||
public static final IntPropertyDef KAFKA_CACHE_SERVER_RECONNECT_DELAY; | ||
public static final PropertyDef<NonceSupplier> KAFKA_CLIENT_SASL_SCRAM_NONCE; | ||
public static final PropertyDef<String> KAFKA_CLIENT_GROUP_INSTANCE_ID; | ||
public static final IntPropertyDef KAFKA_CLIENT_GROUP_REBALANCE_TIMEOUT; | ||
public static final PropertyDef<String> KAFKA_CLIENT_ID; | ||
public static final PropertyDef<InstanceIdSupplier> KAFKA_CLIENT_INSTANCE_ID_SUPPLIER; | ||
|
||
private static final ConfigurationDef KAFKA_CONFIG; | ||
|
||
|
@@ -100,6 +105,11 @@ public class KafkaConfiguration extends Configuration | |
KAFKA_CACHE_CLIENT_TRAILERS_SIZE_MAX = config.property("cache.client.trailers.size.max", 256); | ||
KAFKA_CLIENT_SASL_SCRAM_NONCE = config.property(NonceSupplier.class, "client.sasl.scram.nonce", | ||
KafkaConfiguration::decodeNonceSupplier, KafkaConfiguration::defaultNonceSupplier); | ||
KAFKA_CLIENT_GROUP_INSTANCE_ID = config.property("client.group.instance.id", UUID.randomUUID().toString()); | ||
KAFKA_CLIENT_GROUP_REBALANCE_TIMEOUT = config.property("client.group.rebalance.timeout", 4000); | ||
KAFKA_CLIENT_ID = config.property("client.id", "zilla"); | ||
KAFKA_CLIENT_INSTANCE_ID_SUPPLIER = config.property(InstanceIdSupplier.class, "client.instance.id.supplier", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove What is the difference between If they represent the same concept then we just need |
||
KafkaConfiguration::decodeInstanceIdSupplier, KafkaConfiguration::defaultInstanceIdSupplier); | ||
KAFKA_CONFIG = config; | ||
} | ||
|
||
|
@@ -248,6 +258,21 @@ public int cacheClientTrailersSizeMax() | |
return KAFKA_CACHE_CLIENT_TRAILERS_SIZE_MAX.getAsInt(this); | ||
} | ||
|
||
public String clientGroupInstanceId() | ||
{ | ||
return KAFKA_CLIENT_GROUP_INSTANCE_ID.get(this); | ||
} | ||
|
||
public String clientId() | ||
{ | ||
return KAFKA_CLIENT_ID.get(this); | ||
} | ||
|
||
public int clientGroupRebalanceTimeout() | ||
{ | ||
return KAFKA_CLIENT_GROUP_REBALANCE_TIMEOUT.getAsInt(this); | ||
} | ||
|
||
private static Path cacheDirectory( | ||
Configuration config, | ||
String cacheDirectory) | ||
|
@@ -267,6 +292,11 @@ public Supplier<String> nonceSupplier() | |
return KAFKA_CLIENT_SASL_SCRAM_NONCE.get(this)::get; | ||
} | ||
|
||
public Supplier<String> clientInstanceIdSupplier() | ||
{ | ||
return KAFKA_CLIENT_INSTANCE_ID_SUPPLIER.get(this)::get; | ||
} | ||
|
||
@FunctionalInterface | ||
private interface NonceSupplier | ||
{ | ||
|
@@ -315,4 +345,22 @@ private static NonceSupplier defaultNonceSupplier( | |
return () -> | ||
new BigInteger(130, new SecureRandom()).toString(Character.MAX_RADIX); | ||
} | ||
|
||
@FunctionalInterface | ||
private interface InstanceIdSupplier extends Supplier<String> | ||
{ | ||
} | ||
|
||
private static InstanceIdSupplier decodeInstanceIdSupplier( | ||
Configuration config, | ||
String value) | ||
{ | ||
return () -> String.format("%s-%s", "zilla", UUID.randomUUID()); | ||
} | ||
|
||
private static InstanceIdSupplier defaultInstanceIdSupplier( | ||
Configuration config) | ||
{ | ||
return () -> String.format("%s-%s", "zilla", UUID.randomUUID()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the Note: we have access to the config, so it's easy to extract it as a local final variable before using it in the lambda. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,8 @@ public KafkaCacheClientFactory( | |
final KafkaCacheClientDescribeFactory cacheDescribeFactory = new KafkaCacheClientDescribeFactory( | ||
config, context, bindings::get, supplyCacheRoute); | ||
|
||
final KafkaCacheGroupFactory cacheGroupFactory = new KafkaCacheGroupFactory(config, context, bindings::get); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If implementations of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense thanks |
||
final KafkaCacheClientFetchFactory cacheFetchFactory = new KafkaCacheClientFetchFactory( | ||
config, context, bindings::get, accountant::supplyDebitor, supplyCache, supplyCacheRoute); | ||
|
||
|
@@ -76,6 +78,7 @@ public KafkaCacheClientFactory( | |
final Int2ObjectHashMap<BindingHandler> factories = new Int2ObjectHashMap<>(); | ||
factories.put(KafkaBeginExFW.KIND_META, cacheMetaFactory); | ||
factories.put(KafkaBeginExFW.KIND_DESCRIBE, cacheDescribeFactory); | ||
factories.put(KafkaBeginExFW.KIND_GROUP, cacheGroupFactory); | ||
factories.put(KafkaBeginExFW.KIND_FETCH, cacheFetchFactory); | ||
factories.put(KafkaBeginExFW.KIND_PRODUCE, cacheProduceFactory); | ||
factories.put(KafkaBeginExFW.KIND_MERGED, cacheMergedFactory); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be of type
Duration
, with defaultPT4S
(period time 4 seconds).