Răsfoiți Sursa

kafka message optimize

MaxKey 3 ani în urmă
părinte
comite
98c1166176

+ 3 - 3
maxkey-core/src/main/java/org/maxkey/autoconfigure/ApplicationAutoConfiguration.java

@@ -105,10 +105,10 @@ public class ApplicationAutoConfiguration  implements InitializingBean {
         PasswordEncoder passwordEncoder =
             new DelegatingPasswordEncoder(idForEncode, encoders);
        
-        if(_logger.isDebugEnabled()) {
-        	 _logger.debug("Password Encoders :");
+        if(_logger.isTraceEnabled()) {
+        	 _logger.trace("Password Encoders :");
 	        for (String key : encoders.keySet()) {
-	            _logger.debug("{}= {}" ,String.format("%-10s", key), encoders.get(key).getClass().getName());
+	            _logger.trace("{}= {}" ,String.format("%-10s", key), encoders.get(key).getClass().getName());
 	        }
         }
         _logger.debug("{} is default encoder" , idForEncode);

+ 13 - 2
maxkey-persistence/src/main/java/org/maxkey/persistence/kafka/KafkaMessage.java

@@ -23,7 +23,7 @@ public class KafkaMessage {
     String actionType;
     String sendTime;
     String msgId;
-    String content;
+    Object content;
 
     public String getTopic() {
         return topic;
@@ -61,10 +61,21 @@ public class KafkaMessage {
         return content;
     }
 
-    public void setContent(String content) {
+    public void setContent(Object content) {
         this.content = content;
     }
 
     public KafkaMessage() {
     }
+
+	public KafkaMessage(String topic, String actionType, String sendTime, String msgId, Object content) {
+		super();
+		this.topic = topic;
+		this.actionType = actionType;
+		this.sendTime = sendTime;
+		this.msgId = msgId;
+		this.content = content;
+	}
+    
+    
 }

+ 13 - 22
maxkey-persistence/src/main/java/org/maxkey/persistence/kafka/KafkaPersistService.java

@@ -20,6 +20,7 @@ package org.maxkey.persistence.kafka;
 import java.util.UUID;
 
 import org.maxkey.configuration.ApplicationConfig;
+import org.maxkey.pretty.PrettyFactory;
 import org.maxkey.util.DateUtils;
 import org.maxkey.util.JsonUtils;
 import org.slf4j.Logger;
@@ -30,7 +31,6 @@ import org.springframework.stereotype.Component;
 
 @Component
 public class KafkaPersistService {
-    
     private static final Logger _logger = LoggerFactory.getLogger(KafkaPersistService.class);
     
     @Autowired
@@ -58,29 +58,24 @@ public class KafkaPersistService {
      * @param actionType CREATE UPDATE DELETE
      */
     public void send(String topic,Object content,String actionType) {
-        //config.identity.kafkasupport , if true 
+        //maxkey.server.kafka.support , if true 
         if(applicationConfig.isKafkaSupport()) {
-            KafkaMessage message = new KafkaMessage();
-            //message id is uuid
-            message.setMsgId(UUID.randomUUID().toString());
-            message.setActionType(actionType);
-            message.setTopic(topic);
-            //send to kafka time
-            message.setSendTime(DateUtils.getCurrentDateTimeAsString());
-            //content Object to json message content
-            message.setContent(JsonUtils.gson2Json(content));
+            KafkaMessage message = 
+            		new KafkaMessage(
+            				topic,	//kafka TOPIC
+            				actionType,	//action of content
+            				DateUtils.getCurrentDateTimeAsString(),	//send to kafka time
+            				UUID.randomUUID().toString(),	//message id as uuid
+            				content 	//content Object to json message content
+            				);
             String msg = JsonUtils.gson2Json(message);
-            _logger.debug("send  message = {}", msg);
-            //通过线程发送Kafka消息
+            //sand msg to Kafka topic
             KafkaProvisioningThread thread = 
                     new  KafkaProvisioningThread(kafkaTemplate,topic,msg);
-            
             thread.start();
         }
     }
     
-    
-    
     /**
      * KafkaProvisioningThread for send message
      *
@@ -97,20 +92,16 @@ public class KafkaPersistService {
                                 KafkaTemplate<String, String> kafkaTemplate, 
                                 String topic, 
                                 String msg) {
-            
             this.kafkaTemplate = kafkaTemplate;
             this.topic = topic;
             this.msg = msg;
-            
         }
 
         @Override
         public void run() {
-        	_logger.trace("send to Message Queue ...");
+        	_logger.debug("send message \n{}" , PrettyFactory.getJsonPretty().format(msg));
             kafkaTemplate.send(topic, msg);
-            _logger.trace("send to Message Queue finished .");
+            _logger.debug("send to Message Queue finished .");
         }
-
     }
-    
 }

+ 1 - 1
maxkey-webs/maxkey-web-maxkey/src/main/resources/templates/views/safe/setting.ftl

@@ -35,7 +35,7 @@
 				<th><@locale code="userinfo.authnType" /></th>
 				<td nowrap>
 					<select  class="form-control form-select"  name="authnType" id="authnType">
-						<option value="1"  <#if 0==model.authnType >selected</#if>  ><@locale code="button.text.select" /></option>
+						<option value="0"  <#if 0==model.authnType >selected</#if>  ><@locale code="button.text.select" /></option>
 						<option value="1"  <#if 1==model.authnType >selected</#if>  ><@locale code="userinfo.authnType.authnType.1" /></option>
 						<!-- 
 						<option value="2"  <#if 2==model.authnType >selected</#if>  ><@locale code="userinfo.authnType.authnType.2" /></option>