本文整理汇总了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();
}
}