|
|
@ -16,10 +16,9 @@ import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
@Component |
|
|
|
public class DigestionTaskTheadManager { |
|
|
|
// logger |
|
|
@ -52,7 +51,7 @@ public class DigestionTaskTheadManager { |
|
|
|
public void setupMqttBroker() { |
|
|
|
do { |
|
|
|
String uri = UfMdbOption.getString("DigestionTaskMqttBrokerUri", ""); |
|
|
|
String clientId = UfMdbOption.getString("DigestionTaskMqttClientId", ""); |
|
|
|
String clientId = UUID.randomUUID().toString(); |
|
|
|
String myTopic = UfMdbOption.getString("DigestionTaskMqttMyTopic", ""); |
|
|
|
|
|
|
|
UfCommon.delay(1000); |
|
|
@ -63,12 +62,21 @@ public class DigestionTaskTheadManager { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
|
|
|
|
this.client.setCallback(new MqttCallback() { |
|
|
|
this.client.setCallback(new MqttCallbackExtended() { |
|
|
|
@Override |
|
|
|
public void connectComplete(boolean b, String s) { |
|
|
|
try { |
|
|
|
DigestionTaskTheadManager.this.client.subscribe(myTopic, 2); |
|
|
|
LOG.info("[MQTT Server] : subscribed {}", myTopic); |
|
|
|
} catch (MqttException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
public void messageArrived(String topic, MqttMessage message) { |
|
|
|
DigestionTaskTheadManager.this.handleOnMessageArrived(topic, message); |
|
|
|
} |
|
|
|
public void connectionLost(Throwable cause) { |
|
|
|
UfMdbNotification.error("消解任务 MQTT 服务器断开连接"); |
|
|
|
// UfMdbNotification.error("消解任务 MQTT 服务器断开连接"); |
|
|
|
LOG.info("[MQTT Server] : connection lost {}", cause.getMessage()); |
|
|
|
} |
|
|
|
public void deliveryComplete(IMqttDeliveryToken token) {} |
|
|
@ -84,14 +92,6 @@ public class DigestionTaskTheadManager { |
|
|
|
this.client = null; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
client.subscribe(myTopic, 2); |
|
|
|
LOG.info("[MQTT Server] : subscribed {}", myTopic); |
|
|
|
} catch (MqttException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
|
|
|
|
break ; |
|
|
|
} while ( true ); |
|
|
|
} |
|
|
@ -125,7 +125,7 @@ public class DigestionTaskTheadManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
String taskId = actionJsonTree.get("taskId").asText(); |
|
|
|
String taskId = actionJsonTree.get("batchNo").asText(); |
|
|
|
DigestionTaskThread task = null; |
|
|
|
for ( var t : this.tasks ) { |
|
|
|
if ( t.getOutTaskId().equals(taskId) ) { |
|
|
@ -142,7 +142,7 @@ public class DigestionTaskTheadManager { |
|
|
|
|
|
|
|
// start new digestion |
|
|
|
private void startNewDigestion( JsonNode params ) { |
|
|
|
String taskId = params.get("taskId").asText(); |
|
|
|
String taskId = params.get("batchNo").asText(); |
|
|
|
String name = params.get("name").asText(); |
|
|
|
String batchNo = params.get("batchNo").asText(); |
|
|
|
List<Map<String,Object>> tubes = new ArrayList<>(); |
|
|
|