Skip to content

Commit 39a4679

Browse files
author
kindywu
committed
init
1 parent bf6ca72 commit 39a4679

2 files changed

Lines changed: 51 additions & 13 deletions

File tree

modules/jooby-kafka/src/main/java/io/jooby/kafka/KafkaModule.java

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,41 +55,78 @@
5555
* @since 2.8.5
5656
*/
5757
public class KafkaModule implements Extension {
58+
String producerKey;
59+
String consumerKey;
5860
Properties producerProps;
5961
Properties consumerProps;
6062

6163
/**
62-
* Creates a new kafka module. Value must be:
63-
* - Valid redis URI; or
64-
* - Property name
64+
* Creates a new kafka producer module using the <code>kafka.producer</code> property key.
65+
* This key must be present in the application configuration file, like:
66+
*
67+
* <pre>{@code
68+
* kafka.producer.bootstrap.servers = "localhost:9092"
69+
* kafka.producer.acks = "all"
70+
* kafka.producer.retries = 0
71+
* kafka.producer.key.serializer = "org.apache.kafka.common.serialization.StringSerializer"
72+
* kafka.producer.value.serializer = "org.apache.kafka.common.serialization.StringSerializer"
73+
* }</pre>
74+
*
75+
* Creates a new kafka consumer module using the <code>kafka.consumer</code> property key.
76+
* This key must be present in the application configuration file, like:
77+
*
78+
* <pre>{@code
79+
* kafka.consumer.bootstrap.servers = "localhost:9092"
80+
* kafka.consumer.group.id = "group A"
81+
* kafka.consumer.key.deserializer = "org.apache.kafka.common.serialization.StringDeserializer"
82+
* kafka.consumer.value.deserializer = "org.apache.kafka.common.serialization.StringDeserializer"
83+
* }</pre>
84+
*/
85+
public KafkaModule() {
86+
this("kafka.producer", "kafka.consumer");
87+
}
88+
89+
/**
90+
* Creates a new kafka producer module. The producer parameter can be one of:
91+
*
92+
* - A property key defined in your application configuration file, like <code>producerKey</code>.
93+
*
94+
* @param producerKey Database key
95+
*
96+
* Creates a new kafka consumer module. The consumer parameter can be one of:
97+
*
98+
* - A property key defined in your application configuration file, like <code>consumerKey</code>.
99+
*
100+
* @param consumerKey Database key
101+
*/
102+
public KafkaModule(@Nonnull String producerKey, @Nonnull String consumerKey) {
103+
this.producerKey = producerKey;
104+
this.consumerKey = consumerKey;
105+
}
106+
107+
/**
108+
* Creates a new kafka module.
65109
*
66110
* @param producerProps kafka producer properties.
67111
* @param consumerProps kafka consumer properties.
68112
*/
69113
public KafkaModule(@Nonnull Properties producerProps, @Nonnull Properties consumerProps) {
114+
this("kafka.producer", "kafka.consumer");
70115
this.producerProps = producerProps;
71116
this.consumerProps = consumerProps;
72117
}
73118

74-
/**
75-
* Create a new redis module. The application configuration file must have a redis property, like:
76-
* <pre>
77-
* redis = "redis://localhost:6379"
78-
* </pre>
79-
*/
80-
public KafkaModule() {
81-
}
82119

83120
@Override
84121
public void install(@Nonnull Jooby application) {
85122
Config config = application.getConfig();
86123

87124
if (this.producerProps == null) {
88-
this.producerProps = properties(config, "kafka.producer");
125+
this.producerProps = properties(config, this.producerKey);
89126
}
90127

91128
if (this.consumerProps == null) {
92-
this.consumerProps = properties(config, "kafka.consumer");
129+
this.consumerProps = properties(config, this.consumerKey);
93130
}
94131

95132
ServiceRegistry registry = application.getServices();

modules/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<module>jooby-flyway</module>
3434
<module>jooby-ebean</module>
3535
<module>jooby-redis</module>
36+
<module>jooby-kafka</module>
3637
<module>jooby-caffeine</module>
3738

3839
<module>jooby-jackson</module>

0 commit comments

Comments
 (0)