Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"MqttException: Client is not connected" when building client #5

Open
arthurdeschamps opened this issue Aug 7, 2017 · 13 comments
Open

Comments

@arthurdeschamps
Copy link

When I try to build the client:

application = client.buildApplication(applicationId).build();

I get this exception:

org.eclipse.paho.client.mqttv3.MqttException: Client is not connected
	at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:31)
	at org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:177)
	at org.eclipse.paho.client.mqttv3.MqttAsyncClient.publish(MqttAsyncClient.java:1126)
	at org.eclipse.paho.client.mqttv3.MqttAsyncClient.publish(MqttAsyncClient.java:1089)
	at org.eclipse.paho.client.mqttv3.MqttAsyncClient.publish(MqttAsyncClient.java:1096)
	at org.eclipse.kapua.gateway.client.mqtt.paho.PahoClient.publish(PahoClient.java:249)
	at org.eclipse.kapua.gateway.client.mqtt.paho.PahoClient.publishMqtt(PahoClient.java:244)
	at org.eclipse.kapua.gateway.client.kura.KuraBirthCertificateModule.sendBirthCertificate(KuraBirthCertificateModule.java:173)
	at org.eclipse.kapua.gateway.client.kura.KuraBirthCertificateModule.applicationAdded(KuraBirthCertificateModule.java:125)
	at org.eclipse.kapua.gateway.client.spi.AbstractClient.lambda$notifyAddApplication$1(AbstractClient.java:93)
	at org.eclipse.kapua.gateway.client.spi.AbstractClient.fireModuleEvent(AbstractClient.java:85)
	at org.eclipse.kapua.gateway.client.spi.AbstractClient.notifyAddApplication(AbstractClient.java:93)
	at org.eclipse.kapua.gateway.client.spi.AbstractClient.internalBuildApplication(AbstractClient.java:148)
	at org.eclipse.kapua.gateway.client.spi.AbstractClient$2.build(AbstractClient.java:134)
	at communications.kapua.KapuaClient.<init>(KapuaClient.java:73)
	at simulation.main.Simulation.main(Simulation.java:55)
@GogicM
Copy link

GogicM commented Aug 23, 2017

@arthurdeschamps
Hi. I just used this library, and woks good. Can you provide your code here (or link to your repo)?

@arthurdeschamps
Copy link
Author

Hi. Thanks for the assistance.
Here is the code:

    final int port = 1883;
    final String host = "localhost";
    final String accountName = "kapua-sys";
    final String applicationId = "kapua-iot-gateway-simulation-scm";
    final String clientId = "supply-chain-control-simulation";
    try {
        client = KuraMqttProfile.newProfile(PahoClient.Builder::new)
                .accountName(accountName)
                .clientId(clientId)
                .brokerUrl("tcp://"+host+":"+Integer.toString(port))
                .credentials(userAndPassword(accountName, "kapua-password"))
                .build();

    } catch (Exception e) {
       logger.error(e.getMessage());
    }

    application = client.buildApplication(applicationId).build();

Actually even though this exception occurs everything still works. It would just be cleaner not to have it.

@GogicM
Copy link

GogicM commented Aug 23, 2017

Hm... I don't know it's error, but account name is kapua-sys, but user name is : kapua-broker ... Try to send kapua-broker to credentials(userAndPassword(userName, password)) method

@arthurdeschamps
Copy link
Author

It doesn't solve it :(
I forgot to mention there is another warning just before the exception occurs:
11:20:46.131 [main] WARN org.eclipse.kapua.gateway.client.kura.KuraBirthCertificateModule - Failed to publish birth certificate

@GogicM
Copy link

GogicM commented Aug 23, 2017

Hmm... It si problem with birth certificate. At first connection, it is supposed to client publish birth message to register device (creates new device entry)...I only used FuseClient instead PahoClient. Can you show me publish code?
Also, try to set kapua IP address instead localhost

@ctron
Copy link
Owner

ctron commented Aug 31, 2017

The issue is caused by the fact that the birth certificate is sent out while the client is still disconnected. This will raise an issue when using Paho IIRC. However the birth certificate will also be sent out when the client gets connected. So that is more like an information than a warning in this case.

I am open to suggestions what a good fix could be.

@noumanjamil16
Copy link

11:20:46.131 [main] WARN org.eclipse.kapua.gateway.client.kura.KuraBirthCertificateModule - Failed to publish birth certificate
@GogicM @arthurdeschamps @ctron i am facing same error while running my maven project on eclipse. Please help me.

@ctron
Copy link
Owner

ctron commented Feb 16, 2018

What help do you need? Is there anything not working?

@noumanjamil16
Copy link

I want this exception to be resolved mentioned in comment above

@ctron
Copy link
Owner

ctron commented Feb 16, 2018

Does it cause any troubles?

@noumanjamil16
Copy link

And is there any way to use android dependency? I want to use it in android application with cradle dependencies instead of maven

@noumanjamil16
Copy link

@ctron any guidance on it ?

@ctron
Copy link
Owner

ctron commented Feb 16, 2018

Not really, works the same as all other Java dependencies. Nothing special here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants