mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-07 01:18:27 +08:00
Provision topic to database
This commit is contained in:
parent
de6c72ff0f
commit
763a4603d0
@ -19,11 +19,14 @@ package org.maxkey.provision;
|
|||||||
|
|
||||||
public class ProvisionMessage {
|
public class ProvisionMessage {
|
||||||
|
|
||||||
String id;
|
String id;
|
||||||
String topic;
|
String topic;
|
||||||
String actionType;
|
String actionType;
|
||||||
String sendTime;
|
String sendTime;
|
||||||
Object content;
|
String content;
|
||||||
|
int connected;
|
||||||
|
|
||||||
|
Object sourceObject;
|
||||||
|
|
||||||
public String getTopic() {
|
public String getTopic() {
|
||||||
return topic;
|
return topic;
|
||||||
@ -61,20 +64,37 @@ public class ProvisionMessage {
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContent(Object content) {
|
public void setContent(String content) {
|
||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProvisionMessage() {
|
public int getConnected() {
|
||||||
|
return connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnected(int connected) {
|
||||||
|
this.connected = connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getSourceObject() {
|
||||||
|
return sourceObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceObject(Object sourceObject) {
|
||||||
|
this.sourceObject = sourceObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProvisionMessage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProvisionMessage(String id,String topic, String actionType, String sendTime, Object content) {
|
public ProvisionMessage(String id,String topic, String actionType, String sendTime, String content,Object sourceObject) {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.topic = topic;
|
this.topic = topic;
|
||||||
this.actionType = actionType;
|
this.actionType = actionType;
|
||||||
this.sendTime = sendTime;
|
this.sendTime = sendTime;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
|
this.sourceObject = sourceObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -22,10 +22,10 @@ import java.util.UUID;
|
|||||||
import org.maxkey.configuration.ApplicationConfig;
|
import org.maxkey.configuration.ApplicationConfig;
|
||||||
import org.maxkey.provision.thread.ProvisioningThread;
|
import org.maxkey.provision.thread.ProvisioningThread;
|
||||||
import org.maxkey.util.DateUtils;
|
import org.maxkey.util.DateUtils;
|
||||||
import org.maxkey.util.JsonUtils;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ -33,17 +33,10 @@ public class ProvisionService {
|
|||||||
private static final Logger _logger = LoggerFactory.getLogger(ProvisionService.class);
|
private static final Logger _logger = LoggerFactory.getLogger(ProvisionService.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected ApplicationConfig applicationConfig;
|
ApplicationConfig applicationConfig;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
public void setApplicationConfig(ApplicationConfig applicationConfig) {
|
JdbcTemplate jdbcTemplate;
|
||||||
this.applicationConfig = applicationConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public ApplicationConfig getApplicationConfig() {
|
|
||||||
return applicationConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* send msg to jdbc
|
* send msg to jdbc
|
||||||
@ -60,18 +53,31 @@ public class ProvisionService {
|
|||||||
topic, //TOPIC
|
topic, //TOPIC
|
||||||
actionType, //action of content
|
actionType, //action of content
|
||||||
DateUtils.getCurrentDateTimeAsString(), //send time
|
DateUtils.getCurrentDateTimeAsString(), //send time
|
||||||
content //content Object to json message content
|
null, //content Object to json message content
|
||||||
|
content
|
||||||
);
|
);
|
||||||
String msg = JsonUtils.gson2Json(message);
|
|
||||||
//sand msg to provision topic
|
//sand msg to provision topic
|
||||||
Thread thread = null;
|
Thread thread = null;
|
||||||
if(applicationConfig.getMessageQueue().equalsIgnoreCase("provision")) {
|
if(applicationConfig.getMessageQueue().equalsIgnoreCase("provision")) {
|
||||||
_logger.trace("message...");
|
_logger.trace("message...");
|
||||||
thread = new ProvisioningThread(topic,msg);
|
thread = new ProvisioningThread(jdbcTemplate,message);
|
||||||
|
thread.start();
|
||||||
}else{
|
}else{
|
||||||
_logger.trace("no send message...");
|
_logger.trace("no send message...");
|
||||||
}
|
}
|
||||||
thread.start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setApplicationConfig(ApplicationConfig applicationConfig) {
|
||||||
|
this.applicationConfig = applicationConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationConfig getApplicationConfig() {
|
||||||
|
return applicationConfig;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,9 +16,15 @@
|
|||||||
|
|
||||||
package org.maxkey.provision.thread;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provisioning Thread for send message
|
* Provisioning Thread for send message
|
||||||
@ -27,21 +33,31 @@ import org.slf4j.LoggerFactory;
|
|||||||
public class ProvisioningThread extends Thread{
|
public class ProvisioningThread extends Thread{
|
||||||
private static final Logger _logger = LoggerFactory.getLogger(ProvisioningThread.class);
|
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(
|
public ProvisioningThread(JdbcTemplate jdbcTemplate,
|
||||||
String topic,
|
ProvisionMessage msg) {
|
||||||
String msg) {
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
this.topic = topic;
|
|
||||||
this.msg = msg;
|
this.msg = msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
_logger.debug("send message \n{}" , PrettyFactory.getJsonPretty().format(msg));
|
_logger.debug("send message \n{}" ,new JsonPretty().jacksonFormat(msg.getSourceObject()));
|
||||||
//kafkaTemplate.send(topic, msg);
|
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 .");
|
_logger.debug("send to Message Queue finished .");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user