|
55 | 55 | * @since 2.8.5 |
56 | 56 | */ |
57 | 57 | public class KafkaModule implements Extension { |
| 58 | + String producerKey; |
| 59 | + String consumerKey; |
58 | 60 | Properties producerProps; |
59 | 61 | Properties consumerProps; |
60 | 62 |
|
61 | 63 | /** |
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. |
65 | 109 | * |
66 | 110 | * @param producerProps kafka producer properties. |
67 | 111 | * @param consumerProps kafka consumer properties. |
68 | 112 | */ |
69 | 113 | public KafkaModule(@Nonnull Properties producerProps, @Nonnull Properties consumerProps) { |
| 114 | + this("kafka.producer", "kafka.consumer"); |
70 | 115 | this.producerProps = producerProps; |
71 | 116 | this.consumerProps = consumerProps; |
72 | 117 | } |
73 | 118 |
|
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 | | - } |
82 | 119 |
|
83 | 120 | @Override |
84 | 121 | public void install(@Nonnull Jooby application) { |
85 | 122 | Config config = application.getConfig(); |
86 | 123 |
|
87 | 124 | if (this.producerProps == null) { |
88 | | - this.producerProps = properties(config, "kafka.producer"); |
| 125 | + this.producerProps = properties(config, this.producerKey); |
89 | 126 | } |
90 | 127 |
|
91 | 128 | if (this.consumerProps == null) { |
92 | | - this.consumerProps = properties(config, "kafka.consumer"); |
| 129 | + this.consumerProps = properties(config, this.consumerKey); |
93 | 130 | } |
94 | 131 |
|
95 | 132 | ServiceRegistry registry = application.getServices(); |
|
0 commit comments