mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-06 17:08:29 +08:00
Provision topic to database
This commit is contained in:
parent
de6c72ff0f
commit
763a4603d0
@ -23,7 +23,10 @@ public class ProvisionMessage {
|
||||
String topic;
|
||||
String actionType;
|
||||
String sendTime;
|
||||
Object content;
|
||||
String content;
|
||||
int connected;
|
||||
|
||||
Object sourceObject;
|
||||
|
||||
public String getTopic() {
|
||||
return topic;
|
||||
@ -61,20 +64,37 @@ public class ProvisionMessage {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(Object content) {
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
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();
|
||||
this.id = id;
|
||||
this.topic = topic;
|
||||
this.actionType = actionType;
|
||||
this.sendTime = sendTime;
|
||||
this.content = content;
|
||||
this.sourceObject = sourceObject;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -22,10 +22,10 @@ import java.util.UUID;
|
||||
import org.maxkey.configuration.ApplicationConfig;
|
||||
import org.maxkey.provision.thread.ProvisioningThread;
|
||||
import org.maxkey.util.DateUtils;
|
||||
import org.maxkey.util.JsonUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ -33,17 +33,10 @@ public class ProvisionService {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(ProvisionService.class);
|
||||
|
||||
@Autowired
|
||||
protected ApplicationConfig applicationConfig;
|
||||
ApplicationConfig applicationConfig;
|
||||
|
||||
|
||||
public void setApplicationConfig(ApplicationConfig applicationConfig) {
|
||||
this.applicationConfig = applicationConfig;
|
||||
}
|
||||
|
||||
|
||||
public ApplicationConfig getApplicationConfig() {
|
||||
return applicationConfig;
|
||||
}
|
||||
@Autowired
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
/**
|
||||
* send msg to jdbc
|
||||
@ -60,18 +53,31 @@ public class ProvisionService {
|
||||
topic, //TOPIC
|
||||
actionType, //action of content
|
||||
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
|
||||
Thread thread = null;
|
||||
if(applicationConfig.getMessageQueue().equalsIgnoreCase("provision")) {
|
||||
_logger.trace("message...");
|
||||
thread = new ProvisioningThread(topic,msg);
|
||||
thread = new ProvisioningThread(jdbcTemplate,message);
|
||||
thread.start();
|
||||
}else{
|
||||
_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;
|
||||
|
||||
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 (? , ? , ? , ? , ? , ? )";
|
||||
|
||||
String msg;
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
public ProvisioningThread(
|
||||
String topic,
|
||||
String msg) {
|
||||
this.topic = topic;
|
||||
ProvisionMessage msg;
|
||||
|
||||
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));
|
||||
//kafkaTemplate.send(topic, 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 .");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user