-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAFKA-527 FEAT Allow overriding of producer creation (#619)
- Loading branch information
1 parent
4b3b1b7
commit 245ce26
Showing
3 changed files
with
128 additions
and
27 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
kafka/src/main/java/io/micronaut/configuration/kafka/DefaultProducerFactory.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,52 @@ | ||
/* | ||
* Copyright 2017-2022 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.configuration.kafka; | ||
|
||
import java.util.Properties; | ||
|
||
import io.micronaut.context.annotation.Factory; | ||
import io.micronaut.core.annotation.NonNull; | ||
import org.apache.kafka.clients.producer.KafkaProducer; | ||
import org.apache.kafka.clients.producer.Producer; | ||
import org.apache.kafka.common.serialization.Serializer; | ||
|
||
/** | ||
* A default implementation of {@link ProducerFactory} used for creating producer. | ||
* | ||
* @author milanspre | ||
* @since 5.0.0 | ||
*/ | ||
@Factory | ||
public class DefaultProducerFactory implements ProducerFactory { | ||
|
||
/** | ||
* | ||
* Creates kafka producer, could be overridden for further control. | ||
* | ||
* @param config properties for producer | ||
* @param ks key serializer | ||
* @param vs value serializer | ||
* @param <K> key type | ||
* @param <V> value type | ||
* @since 5.0.0 | ||
* @return new instance of producer | ||
*/ | ||
@Override | ||
@NonNull | ||
public <K, V> Producer<K, V> createProducer(Properties config, Serializer<K> ks, Serializer<V> vs) { | ||
return new KafkaProducer<>(config, ks, vs); | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
kafka/src/main/java/io/micronaut/configuration/kafka/ProducerFactory.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,46 @@ | ||
/* | ||
* Copyright 2017-2022 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.configuration.kafka; | ||
|
||
import java.util.Properties; | ||
|
||
import io.micronaut.core.annotation.NonNull; | ||
import org.apache.kafka.clients.producer.Producer; | ||
import org.apache.kafka.common.serialization.Serializer; | ||
|
||
/** | ||
* A factory class for creating Kafka {@link org.apache.kafka.clients.producer.Producer} instances. | ||
* | ||
* @author milanspre | ||
* @since 5.0.0 | ||
*/ | ||
public interface ProducerFactory { | ||
|
||
/** | ||
* | ||
* Creates kafka producer, could be overridden for further control. | ||
* | ||
* @param config properties for producer | ||
* @param ks key serializer | ||
* @param vs value serializer | ||
* @param <K> key type | ||
* @param <V> value type | ||
* @since 5.0.0 | ||
* @return new instance of producer | ||
*/ | ||
@NonNull | ||
<K, V> Producer<K, V> createProducer(Properties config, Serializer<K> ks, Serializer<V> vs); | ||
} |