【问题标题】:Spring-Kafka seems to stop Spring Boot web to run correctlySpring-Kafka 似乎阻止 Spring Boot web 正常运行
【发布时间】:2019-12-11 21:41:47
【问题描述】:

我正在尝试在 Spring Boot 应用程序中使用 Spring-Kafka 进行一些试验。

我的 application.properties 中显示了一个非常简单的配置

spring.kafka.consumer.bootstrap-servers=127.0.0.1:29092
spring.kafka.consumer.group-id=myGroup

Kafka 在容器中运行。

现在,连接似乎工作正常,我可以发送消息,但是发生了一些奇怪的事情。

我一介绍:

(在 Kotlin 中)

@KafkaListener(topics = arrayOf("kotlinTestTopic"))
    fun listenAsObject(@Payload data : String) {
        println(data)
    }

我的网络控制器都没有工作了,我收到“连接被拒绝”,好像 Spring Boot 启动没有完成一样。

只要我把它注释掉,控制器就回来了。

任何提示我做错了什么?

编辑

这里是启动日志:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.2.RELEASE)

2019-12-11 14:24:50.552  INFO 10659 --- [           main] t.g.com.testboot.TestbootApplicationKt   : Starting TestbootApplicationKt on theirish-ThinkPad-L390 with PID 10659 (/home/theirish/Documenti/programming/testboot/build/classes/kotlin/main started by theirish in /home/theirish/Documenti/programming/testboot)
2019-12-11 14:24:50.554  INFO 10659 --- [           main] t.g.com.testboot.TestbootApplicationKt   : No active profile set, falling back to default profiles: default
2019-12-11 14:24:50.651  WARN 10659 --- [kground-preinit] o.s.h.c.j.Jackson2ObjectMapperBuilder    : For Jackson Kotlin classes support please add "com.fasterxml.jackson.module:jackson-module-kotlin" to the classpath
2019-12-11 14:24:51.031  INFO 10659 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2019-12-11 14:24:51.112  INFO 10659 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 40ms. Found 4 JPA repository interfaces.
2019-12-11 14:24:51.476  INFO 10659 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-12-11 14:24:51.680  INFO 10659 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-12-11 14:24:51.689  INFO 10659 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-12-11 14:24:51.689  INFO 10659 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.29]
2019-12-11 14:24:51.767  INFO 10659 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-12-11 14:24:51.767  INFO 10659 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1172 ms
2019-12-11 14:24:51.894  INFO 10659 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2019-12-11 14:24:51.936  INFO 10659 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.4.9.Final}
2019-12-11 14:24:52.065  INFO 10659 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2019-12-11 14:24:52.129  INFO 10659 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2019-12-11 14:24:52.235  INFO 10659 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2019-12-11 14:24:52.245  INFO 10659 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2019-12-11 14:24:52.778  INFO 10659 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2019-12-11 14:24:52.783  INFO 10659 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-12-11 14:24:53.366  WARN 10659 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-12-11 14:24:53.483  INFO 10659 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-12-11 14:24:53.739  INFO 10659 --- [           main] o.a.k.clients.admin.AdminClientConfig    : AdminClientConfig values: 
    bootstrap.servers = [127.0.0.1:29092]
    client.dns.lookup = default
    client.id = 
    connections.max.idle.ms = 300000
    metadata.max.age.ms = 300000
    metric.reporters = []
    metrics.num.samples = 2
    metrics.recording.level = INFO
    metrics.sample.window.ms = 30000
    receive.buffer.bytes = 65536
    reconnect.backoff.max.ms = 1000
    reconnect.backoff.ms = 50
    request.timeout.ms = 120000
    retries = 5
    retry.backoff.ms = 100
    sasl.client.callback.handler.class = null
    sasl.jaas.config = null
    sasl.kerberos.kinit.cmd = /usr/bin/kinit
    sasl.kerberos.min.time.before.relogin = 60000
    sasl.kerberos.service.name = null
    sasl.kerberos.ticket.renew.jitter = 0.05
    sasl.kerberos.ticket.renew.window.factor = 0.8
    sasl.login.callback.handler.class = null
    sasl.login.class = null
    sasl.login.refresh.buffer.seconds = 300
    sasl.login.refresh.min.period.seconds = 60
    sasl.login.refresh.window.factor = 0.8
    sasl.login.refresh.window.jitter = 0.05
    sasl.mechanism = GSSAPI
    security.protocol = PLAINTEXT
    send.buffer.bytes = 131072
    ssl.cipher.suites = null
    ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
    ssl.endpoint.identification.algorithm = https
    ssl.key.password = null
    ssl.keymanager.algorithm = SunX509
    ssl.keystore.location = null
    ssl.keystore.password = null
    ssl.keystore.type = JKS
    ssl.protocol = TLS
    ssl.provider = null
    ssl.secure.random.implementation = null
    ssl.trustmanager.algorithm = PKIX
    ssl.truststore.location = null
    ssl.truststore.password = null
    ssl.truststore.type = JKS

2019-12-11 14:24:53.803  INFO 10659 --- [           main] o.a.kafka.common.utils.AppInfoParser     : Kafka version: 2.3.1
2019-12-11 14:24:53.803  INFO 10659 --- [           main] o.a.kafka.common.utils.AppInfoParser     : Kafka commitId: 18a913733fb71c01
2019-12-11 14:24:53.803  INFO 10659 --- [           main] o.a.kafka.common.utils.AppInfoParser     : Kafka startTimeMs: 1576070693802

【问题讨论】:

  • 能否添加您在控制台帖子中看到的启动日志添加上述代码?

标签: spring-boot spring-kafka


【解决方案1】:

我现在感觉非常愚蠢。

显然,在我的实验中,我在 Spring-Kafka 配置中引入了错误的 Kafka 端口。作为一个副作用,整个 Spring Boot 应用程序都挂了,这是非常出乎意料的......

【讨论】:

  • 是的,如果 spring 无法连接到 kafka 代理,应用程序将无法正确启动。
  • 将容器属性missingTopicsFatal 设置为false 以防止在启动期间尝试连接到Kafka。自2.3.4以来默认为false。
猜你喜欢
  • 1970-01-01
  • 2021-06-20
  • 2015-06-28
  • 2017-11-11
  • 1970-01-01
  • 2017-11-13
  • 1970-01-01
  • 2021-08-17
  • 2017-10-28
相关资源
最近更新 更多