SmartsquareGmbH / mqtt-starter

HiveMQ Spring Boot Starter
MIT License
15 stars 5 forks source link

connection timeout #5

Closed zamek42 closed 7 months ago

zamek42 commented 3 years ago

Hi, I would like to use your project. I want to use it with mqtt3 only.

my mqtt params in my application.yaml is:

mqtt: host: @mqtt.url.develop@ port: @mqtt.port.develop@ client-id: @mqtt.clientID.develop@ username: @mqtt.user.develop@ password: @mqtt.password.develop@ version: 3 ssl: false clean: true

When I start my spring project I get this error :

d.s.s.mqtt.SpringAwareMqtt3Client - Connecting to aaaaaaaa@tcp://xxxxxxxxxxxxxxxxx:1883 using mqtt 3... 2021-10-07 19:58:48 - WARN - [com.hivemq.client.mqtt-5-1] - d.s.s.m.MqttAutoConfiguration$$EnhancerBySpringCGLIB$$18da2d88 - Disconnected from broker, reconnecting... 2021-10-07 19:58:50 - WARN - [com.hivemq.client.mqtt-5-1] - d.s.s.m.MqttAutoConfiguration$$EnhancerBySpringCGLIB$$18da2d88 - Disconnected from broker, reconnecting... 2021-10-07 19:58:54 - WARN - [com.hivemq.client.mqtt-5-1] - d.s.s.m.MqttAutoConfiguration$$EnhancerBySpringCGLIB$$18da2d88 - Disconnected from broker, reconnecting...

... Error creating bean with name 'mqtt3Client' defined in class path resource [de/smartsquare/starter/mqtt/MqttAutoConfiguration.class]: Invocation of init method failed; nested exception is de.smartsquare.starter.mqtt.BrokerConnectException: Failed to connect: Broker tcp://xxxxxxxxxxxxxxxxx:1883 did not respond within 10 seconds. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1794) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) at com.xxxxxxxxxxxxxxxxxx.main(XXXXXXXXXXXXApplication.kt:47) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) Caused by: de.smartsquare.starter.mqtt.BrokerConnectException: Failed to connect: Broker tcp://xxxxxxxxxxxxxxxxx:1883 did not respond within 10 seconds. at de.smartsquare.starter.mqtt.SpringAwareMqtt3Client.afterPropertiesSet(SpringAwareMqttClient.kt:43) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790) ... 22 common frames omitted

Of course the server is working and another client can connect to there.

thx, Zamek

rubengees commented 3 years ago

Hello!

This looks like either the server is not available from the machine you are working on or some configuration does not match. I just tried locally with the latest version and this configuration works for me on localhost:

mqtt:
  host: localhost
  port: 1883
  client-id: test
  ssl: false
  clean: true
  version: 3

You can try to look at the effective configuration using the MqttProperties class either by injecting it somewhere and looking at it in the debugger or by printing it to the console e.g. using this class:

import de.smartsquare.starter.mqtt.MqttProperties
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.InitializingBean
import org.springframework.stereotype.Component

@Component
class MqttPropertiesPrinter(private val mqttProperties: MqttProperties) : InitializingBean {

    private val logger = LoggerFactory.getLogger(MqttPropertiesPrinter::class.java)

    override fun afterPropertiesSet() {
        logger.info(mqttProperties.toString())
    }
}

If that does not help, what is the broker you are trying to connect to?

rubengees commented 7 months ago

Closing for now. Please reopen or create a new issue if you have more input :slightly_smiling_face:.