chia7712 commented on code in PR #17666:
URL: https://github.com/apache/kafka/pull/17666#discussion_r1833259082
##########
test-common/test-common-api/src/main/java/org/apache/kafka/common/test/api/ClusterInstance.java:
##########
@@ -147,10 +157,62 @@ default <T> T getUnderlying(Class<T> asClass) {
return asClass.cast(getUnderlying());
}
- Admin createAdminClient(Properties configOverrides);
+
//---------------------------[producer/consumer/admin]---------------------------//
+
+ default <K, V> Producer<K, V> producer(Map<String, Object> configs,
+ Serializer<K> keySerializer,
+ Serializer<V> valueSerializer
+ ) {
+ Properties props = new Properties();
+ props.putAll(configs);
+ props.putIfAbsent(ProducerConfig.ACKS_CONFIG, "-1");
+ props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers());
+ props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
keySerializer.getClass().getName());
+ props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
valueSerializer.getClass().getName());
+ return new KafkaProducer<>(props);
+ }
+
+ default <K, V> Producer<K, V> producer(Serializer<K> keySerializer,
+ Serializer<V> valueSerializer
+ ) {
+ return producer(Map.of(), keySerializer, valueSerializer);
+ }
+
+ default <K, V> Consumer<K, V> consumer(Map<String, Object> configs,
+ Deserializer<V> valueDeserializer
+ ) {
+ Properties props = new Properties();
+ props.putAll(configs);
+ props.putIfAbsent(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+ props.putIfAbsent(ConsumerConfig.GROUP_ID_CONFIG, "group_" +
TestUtils.randomString(5));
+ props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers());
+ props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
valueDeserializer.getClass().getName());
Review Comment:
we should use `valueDeserializer` instance passed by users rather than have
another `valueDeserializer` instance.
Personally, it should be fine to encourage users to use `configs` only.
Casting can be addressed by users if they use non-bytes deseralizer
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]