本文整理匯總了Java中org.eclipse.paho.client.mqttv3.MqttClient.setTimeToWait方法的典型用法代碼示例。如果您正苦於以下問題:Java MqttClient.setTimeToWait方法的具體用法?Java MqttClient.setTimeToWait怎麽用?Java MqttClient.setTimeToWait使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.paho.client.mqttv3.MqttClient
的用法示例。
在下文中一共展示了MqttClient.setTimeToWait方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
public void run() {
try {
// Connect to the MQTT Server
MqttConnectOptions options = new MqttConnectOptions();
options.setAutomaticReconnect(true);
options.setCleanSession(true);
options.setConnectionTimeout(30);
options.setKeepAliveInterval(30);
options.setUserName(username);
options.setPassword(password.toCharArray());
client = new MqttClient(serverUrl, clientId);
client.setTimeToWait(5000); // short timeout on failure to connect
client.connect(options);
client.setCallback(this);
// Just listen to all DDATA messages on spAv1.0 topics and wait for inbound messages
client.subscribe("spBv1.0/#", 0);
} catch(Exception e) {
e.printStackTrace();
}
}
示例2: run
import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
public void run() {
try {
// Connect to the MQTT Server
MqttConnectOptions options = new MqttConnectOptions();
options.setAutomaticReconnect(true);
options.setCleanSession(true);
options.setConnectionTimeout(30);
options.setKeepAliveInterval(30);
options.setUserName(username);
options.setPassword(password.toCharArray());
client = new MqttClient(serverUrl, clientId);
client.setTimeToWait(2000);
client.setCallback(this);
client.connect(options);
// Subscribe to control/command messages for both the edge of network node and the attached devices
client.subscribe(NAMESPACE + "/" + groupId + "/+/" + edgeNode, 0);
client.subscribe(NAMESPACE + "/" + groupId + "/+/" + edgeNode + "/*", 0);
// Loop to receive input commands
while (true) {
System.out.print("\n> ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
handleCommand(line);
}
} catch(Exception e) {
e.printStackTrace();
}
}
示例3: run
import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
public void run() {
try {
// Random generator and thread pool for outgoing published messages
executor = Executors.newFixedThreadPool(1);
// Build up DEATH payload - note DEATH payloads don't have a regular sequence number
SparkplugBPayloadBuilder deathPayload = new SparkplugBPayloadBuilder().setTimestamp(new Date());
deathPayload = addBdSeqNum(deathPayload);
byte [] deathBytes = new SparkplugBPayloadEncoder().getBytes(deathPayload.createPayload());
MqttConnectOptions options = new MqttConnectOptions();
if (USING_REAL_TLS) {
SocketFactory sf = SSLSocketFactory.getDefault();
options.setSocketFactory(sf);
}
// Connect to the MQTT Server
options.setAutomaticReconnect(true);
options.setCleanSession(true);
options.setConnectionTimeout(30);
options.setKeepAliveInterval(30);
options.setUserName(username);
options.setPassword(password.toCharArray());
options.setWill(NAMESPACE + "/" + groupId + "/NDEATH/" + edgeNode, deathBytes, 0, false);
client = new MqttClient(serverUrl, clientId);
client.setTimeToWait(2000);
client.setCallback(this); // short timeout on failure to connect
client.connect(options);
// Subscribe to control/command messages for both the edge of network node and the attached devices
client.subscribe(NAMESPACE + "/" + groupId + "/NCMD/" + edgeNode + "/#", 0);
client.subscribe(NAMESPACE + "/" + groupId + "/DCMD/" + edgeNode + "/#", 0);
client.subscribe(NAMESPACE + "/#", 0);
// Loop forever publishing data every PUBLISH_PERIOD
while (true) {
Thread.sleep(PUBLISH_PERIOD);
if (client.isConnected()) {
synchronized(seqLock) {
System.out.println("Connected - publishing new data");
// Create the payload and add some metrics
SparkplugBPayload payload = new SparkplugBPayload(
new Date(),
newMetrics(false),
getSeqNum(),
newUUID(),
null);
client.publish(NAMESPACE + "/" + groupId + "/DDATA/" + edgeNode + "/" + deviceId,
new SparkplugBPayloadEncoder().getBytes(payload), 0, false);
}
} else {
System.out.println("Not connected - not publishing data");
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
示例4: run
import org.eclipse.paho.client.mqttv3.MqttClient; //導入方法依賴的package包/類
public void run() {
try {
// Random generator and thread pool for outgoing published messages
executor = Executors.newFixedThreadPool(1);
// Build up DEATH payload - note DEATH payloads don't have a regular sequence number
SparkplugBPayloadBuilder deathPayload = new SparkplugBPayloadBuilder().setTimestamp(new Date());
deathPayload = addBdSeqNum(deathPayload);
byte[] deathBytes = new SparkplugBPayloadEncoder().getBytes(deathPayload.createPayload());
MqttConnectOptions options = new MqttConnectOptions();
if (USING_REAL_TLS) {
SocketFactory sf = SSLSocketFactory.getDefault();
options.setSocketFactory(sf);
}
// Connect to the MQTT Server
options.setAutomaticReconnect(true);
options.setCleanSession(true);
options.setConnectionTimeout(30);
options.setKeepAliveInterval(30);
options.setUserName(username);
options.setPassword(password.toCharArray());
options.setWill(NAMESPACE + "/" + groupId + "/NDEATH/" + edgeNode, deathBytes, 0, false);
client = new MqttClient(serverUrl, clientId);
client.setTimeToWait(2000);
client.setCallback(this); // short timeout on failure to connect
client.connect(options);
// Subscribe to control/command messages for both the edge of network node and the attached devices
client.subscribe(NAMESPACE + "/" + groupId + "/NCMD/" + edgeNode + "/#", 0);
client.subscribe(NAMESPACE + "/" + groupId + "/DCMD/" + edgeNode + "/#", 0);
// Loop forever publishing data every PUBLISH_PERIOD
while (true) {
Thread.sleep(PUBLISH_PERIOD);
if (client.isConnected()) {
synchronized (seqLock) {
System.out.println("Connected - publishing new data");
// Create the payload and add some metrics
SparkplugBPayload payload = new SparkplugBPayload(new Date(), newComplexTemplateInstance(),
getSeqNum(), newUUID(), null);
client.publish(NAMESPACE + "/" + groupId + "/DDATA/" + edgeNode + "/" + deviceId,
new SparkplugBPayloadEncoder().getBytes(payload), 0, false);
}
} else {
System.out.println("Not connected - not publishing data");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}