|
@@ -16,9 +16,15 @@
|
|
|
|
|
|
package org.maxkey.provision.thread;
|
|
|
|
|
|
-import org.maxkey.pretty.PrettyFactory;
|
|
|
+import java.io.Serializable;
|
|
|
+import java.sql.Types;
|
|
|
+
|
|
|
+import org.maxkey.pretty.impl.JsonPretty;
|
|
|
+import org.maxkey.provision.ProvisionMessage;
|
|
|
+import org.maxkey.util.ObjectTransformer;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
|
|
|
|
|
* Provisioning Thread for send message
|
|
@@ -27,21 +33,31 @@ import org.slf4j.LoggerFactory;
|
|
|
public class ProvisioningThread extends Thread{
|
|
|
private static final Logger _logger = LoggerFactory.getLogger(ProvisioningThread.class);
|
|
|
|
|
|
- String topic ;
|
|
|
+ static final String PROVISION_INSERT_STATEMENT = "insert into mxk_history_provisions(`id`,`topic`,`actiontype`,`content`,`sendtime`,`connected`) values (? , ? , ? , ? , ? , ? )";
|
|
|
+
|
|
|
+ JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
- String msg;
|
|
|
+ ProvisionMessage msg;
|
|
|
|
|
|
- public ProvisioningThread(
|
|
|
- String topic,
|
|
|
- String msg) {
|
|
|
- this.topic = topic;
|
|
|
+ public ProvisioningThread(JdbcTemplate jdbcTemplate,
|
|
|
+ ProvisionMessage msg) {
|
|
|
+ this.jdbcTemplate = jdbcTemplate;
|
|
|
this.msg = msg;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- _logger.debug("send message \n{}" , PrettyFactory.getJsonPretty().format(msg));
|
|
|
-
|
|
|
+ _logger.debug("send message \n{}" ,new JsonPretty().jacksonFormat(msg.getSourceObject()));
|
|
|
+ msg.setContent(ObjectTransformer.serialize((Serializable)msg.getSourceObject()));
|
|
|
+ jdbcTemplate.update(PROVISION_INSERT_STATEMENT,
|
|
|
+ new Object[] {
|
|
|
+ msg.getId(), msg.getTopic(), msg.getActionType(), msg.getContent(),
|
|
|
+ msg.getSendTime(),msg.getConnected()
|
|
|
+ },
|
|
|
+ new int[] {
|
|
|
+ Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
|
|
|
+ Types.TINYINT
|
|
|
+ });
|
|
|
_logger.debug("send to Message Queue finished .");
|
|
|
}
|
|
|
}
|