ProvisionService.java 2.7 KB
Newer Older
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 

M
MaxKey 已提交
18
package org.maxkey.provision;
19 20 21

import java.util.UUID;

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
22
import org.maxkey.configuration.ApplicationConfig;
M
MaxKey 已提交
23
import org.maxkey.provision.thread.ProvisioningThread;
24 25 26 27
import org.maxkey.util.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
M
MaxKey 已提交
28
import org.springframework.jdbc.core.JdbcTemplate;
29 30 31
import org.springframework.stereotype.Component;

@Component
M
MaxKey 已提交
32 33
public class ProvisionService {
    private static final Logger _logger = LoggerFactory.getLogger(ProvisionService.class);
34 35
    
    @Autowired
M
MaxKey 已提交
36
    ApplicationConfig applicationConfig;
37
    
M
MaxKey 已提交
38 39
    @Autowired
    JdbcTemplate jdbcTemplate;
M
MaxKey 已提交
40

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
41
    /**
M
MaxKey 已提交
42 43
     * send  msg to jdbc
     * @param topic TOPIC
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
44 45 46
     * @param content msg Object
     * @param actionType CREATE UPDATE DELETE
     */
47
    public void send(String topic,Object content,String actionType) {
M
MaxKey 已提交
48
        //maxkey.server.message.queue , if not none
49
        if(applicationConfig.isMessageQueueSupport()) {
M
MaxKey 已提交
50 51
            ProvisionMessage message = 
            		new ProvisionMessage(
M
MaxKey 已提交
52
            				UUID.randomUUID().toString(),	//message id as uuid
53 54 55
            				topic,	//TOPIC
            				actionType,	//action of content
            				DateUtils.getCurrentDateTimeAsString(),	//send time
M
MaxKey 已提交
56 57
            				null, 	//content Object to json message content
            				content
M
MaxKey 已提交
58
            				);
M
MaxKey 已提交
59
            //sand msg to provision topic
60
            Thread thread = null;
M
MaxKey 已提交
61 62
            if(applicationConfig.getMessageQueue().equalsIgnoreCase("provision")) {
            	_logger.trace("message...");
M
MaxKey 已提交
63 64
            	thread = new  ProvisioningThread(jdbcTemplate,message);
            	thread.start();
M
MaxKey 已提交
65 66
            }else{
            	_logger.trace("no send message...");
67
            }
68 69
        }
    }
M
MaxKey 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82

	public void setApplicationConfig(ApplicationConfig applicationConfig) {
		this.applicationConfig = applicationConfig;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	public ApplicationConfig getApplicationConfig() {
		return applicationConfig;
	}
	
83
}