|
|
Re: MQTT connection threads are getting hanged. [message #1221906 is a reply to message #1221887] |
Wed, 18 December 2013 17:03 |
uday kumar Messages: 3 Registered: December 2013 |
Junior Member |
|
|
Hi Ian,
Thanks for the Reply.
I have few queries.
Why the threads are not cleared when the connection gets disconnect, i see threads getting increased and causing the thread blocking.
Why the folders are getting created with client id names, when persistence is not used. If this is the case tmp folder gets full,
Is it must to provide unique clientid when new connection is established.
Is there any way to have connection pool kind of thing like cacheconnection pool, to avoid creating connections every time instead reuse from pool.
What is the best way to create connections for publishing,
What does below exception mean from thread dump:
java.lang.Thread.State: WAITING
at java.lang.Object.wait(Native Method)
- waiting on <53000ae6> (a java.lang.Object)
at java.lang.Object.wait(Object.java:503)
at org.eclipse.paho.client.mqttv3.internal.Token.waitForResponse(Token.java:122)
at org.eclipse.paho.client.mqttv3.internal.Token.waitForCompletion(Token.java:90)
at org.eclipse.paho.client.mqttv3.MqttToken.waitForCompletion(MqttToken.java:50)
at org.eclipse.paho.client.mqttv3.MqttClient.publish(MqttClient.java:272)
Here is the code i am using Please suggest best ways to avoid thread blocking and best way to create connection. publish method is called with through put of more than 100 messages per second.
private MqttClient client; //class variable
public MqttClient getNewConnection(String clientId) {
try {
logger.info("Broker Url "+brokerUrl +" clientId "+clientId +" "+tmpDir);
client = new MqttClient(this.brokerUrl, clientId);
// Set this wrapper as the callback handler
client.setCallback(this);
} catch (MqttException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return client;
}
// before every publish check for isConnected if not create new connection and with new clientId.
if(client == null || !client.isConnected())
{
client = getNewConnection(Constants.MQTT_PREFIX + RandomStringUtils.randomAlphanumeric(Constants.MQTT_CLIENT_ID_LEN));
client.connect(conOpt);
}
[Updated on: Thu, 19 December 2013 07:52] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05003 seconds