Skip to content

Commit c6bb655

Browse files
committed
kafka: split kafka configuration
1 parent 7b30a26 commit c6bb655

File tree

5 files changed

+50
-36
lines changed

5 files changed

+50
-36
lines changed

generators/spring-boot/templates/src/main/resources/config/application.yml.ejs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,9 @@ mongock:
171171
172172
<%_ } _%>
173173
spring:
174-
<%_ if (databaseTypeSql && messageBrokerKafka) { _%>
175-
autoconfigure:
176-
exclude: org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration
177-
<%_ } _%>
178174
application:
179175
name: <%= baseName %>
180-
<%_ if (serviceDiscoveryConsul || applicationTypeGateway || messageBrokerKafka) { _%>
176+
<%_ if (serviceDiscoveryConsul || applicationTypeGateway) { _%>
181177
cloud:
182178
<%_ if (serviceDiscoveryConsul) { _%>
183179
consul:
@@ -255,27 +251,6 @@ spring:
255251
# See alternatives in https://github.com/spring-cloud/spring-cloud-gateway/issues/3818
256252
trusted-proxies: '.*'
257253
<%_ } _%>
258-
<%_ if (messageBrokerKafka) { _%>
259-
function:
260-
definition: kafkaConsumer;kafkaProducer
261-
stream:
262-
kafka:
263-
binder:
264-
replicationFactor: 1
265-
auto-create-topics: true
266-
brokers: localhost:9092
267-
bindings:
268-
binding-out-0:
269-
content-type: text/plain
270-
group: <%= dasherizedBaseName %>
271-
kafkaConsumer-in-0:
272-
destination: sse-topic
273-
content-type: text/plain
274-
group: <%= dasherizedBaseName %>
275-
kafkaProducer-out-0:
276-
content-type: text/plain
277-
group: <%= dasherizedBaseName %>
278-
<%_ } _%>
279254
<%_ } _%>
280255
<%_ if ('dockerServices' in locals && dockerServices?.length) { _%>
281256
docker:

generators/spring-cloud/generators/kafka/__snapshots__/generator.spec.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ exports[`generator - spring-cloud:kafka with defaults options should match files
101101
"src/main/java/com/mycompany/myapp/web/rest/JhipsterKafkaResource.java": {
102102
"stateCleared": "modified",
103103
},
104+
"src/main/resources/config/application-kafka.yml": {
105+
"stateCleared": "modified",
106+
},
104107
"src/test/java/com/mycompany/myapp/config/KafkaTestContainer.java": {
105108
"stateCleared": "modified",
106109
},

generators/spring-cloud/generators/kafka/files.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,31 @@
1717
* limitations under the License.
1818
*/
1919
import { asWriteFilesSection } from '../../../base-application/support/task-type-inference.ts';
20-
import { SERVER_MAIN_SRC_DIR, SERVER_TEST_SRC_DIR } from '../../../generator-constants.ts';
21-
import { moveToJavaPackageSrcDir, moveToJavaPackageTestDir } from '../../../java/support/index.ts';
20+
import { SERVER_MAIN_RES_DIR, SERVER_MAIN_SRC_DIR, SERVER_TEST_SRC_DIR } from '../../../generator-constants.ts';
21+
import { moveToJavaPackageSrcDir, moveToJavaPackageTestDir, moveToSrcMainResourcesDir } from '../../../java/support/index.ts';
2222

2323
export const kafkaFiles = asWriteFilesSection({
24-
config: [
25-
{
26-
path: `${SERVER_MAIN_SRC_DIR}_package_/`,
27-
renameTo: moveToJavaPackageSrcDir,
28-
templates: [data => `broker/KafkaConsumer_${data.imperativeOrReactive}.java`, 'broker/KafkaProducer.java'],
29-
},
30-
],
31-
resources: [
24+
base: [
3225
{
3326
path: `${SERVER_MAIN_SRC_DIR}_package_/`,
3427
renameTo: moveToJavaPackageSrcDir,
3528
templates: [
29+
data => `broker/KafkaConsumer_${data.imperativeOrReactive}.java`,
30+
'broker/KafkaProducer.java',
3631
{
3732
sourceFile: data => `web/rest/KafkaResource_${data.imperativeOrReactive}.java`,
3833
destinationFile: data => `web/rest/${data.upperFirstCamelCaseBaseName}KafkaResource.java`,
3934
},
4035
],
4136
},
4237
],
38+
resources: [
39+
{
40+
path: `${SERVER_MAIN_RES_DIR}`,
41+
renameTo: moveToSrcMainResourcesDir,
42+
templates: ['config/application-kafka.yml'],
43+
},
44+
],
4345
test: [
4446
{
4547
path: `${SERVER_TEST_SRC_DIR}_package_/`,

generators/spring-cloud/generators/kafka/generator.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ export default class KafkaGenerator extends SpringBootApplicationGenerator {
3434
}
3535
}
3636

37+
get preparing() {
38+
return this.asPreparingTaskGroup({
39+
preparing({ application }) {
40+
application.devActiveProfiles.push('kafka');
41+
application.prodActiveProfiles.push('kafka');
42+
},
43+
});
44+
}
45+
46+
get [SpringBootApplicationGenerator.PREPARING]() {
47+
return this.delegateTasksToBlueprint(() => this.preparing);
48+
}
49+
3750
get writing() {
3851
return this.asWritingTaskGroup({
3952
async cleanup({ application, control }) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
spring:
2+
cloud:
3+
function:
4+
definition: kafkaConsumer;kafkaProducer
5+
stream:
6+
kafka:
7+
binder:
8+
replicationFactor: 1
9+
auto-create-topics: true
10+
brokers: localhost:9092
11+
bindings:
12+
binding-out-0:
13+
content-type: text/plain
14+
group: <%= dasherizedBaseName %>
15+
kafkaConsumer-in-0:
16+
destination: sse-topic
17+
content-type: text/plain
18+
group: <%= dasherizedBaseName %>
19+
kafkaProducer-out-0:
20+
content-type: text/plain
21+
group: <%= dasherizedBaseName %>

0 commit comments

Comments
 (0)