| 
					
				 | 
			
			
				@ -1,20 +1,6 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.hos.agent.service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.hos.agent.configuration.AgentConfiguration; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.hos.agent.constant.ShellConstant; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.camel.CamelContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.camel.ProducerTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.log4j.LogManager; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.log4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.zbus.broker.ZbusBroker; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.zbus.mq.Consumer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.zbus.net.http.Message; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @author HZY 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -23,54 +9,54 @@ import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class ShellService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final Logger logger = LogManager.getLogger(ShellService.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private ZbusBroker zbusBroker; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private Consumer consumer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private AgentConfiguration configuration; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private CamelContext camelContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void setZbusBroker(ZbusBroker zbusBroker) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        this.zbusBroker = zbusBroker; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void setConfiguration(AgentConfiguration configuration) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        this.configuration = configuration; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void setCamelContext(CamelContext camelContext) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        this.camelContext = camelContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void handle(Message message, Consumer consumer) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String, Object> header = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        header.put("event", message.getHead("event")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ProducerTemplate producerTemplate = camelContext.createProducerTemplate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        producerTemplate.sendBodyAndHeaders(ShellConstant.ENDPOINT, message.getBodyString(), header); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void server() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (zbusBroker == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.error("zbusBroker is null"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consumer = new Consumer(zbusBroker, ShellConstant.PREFIX_IN + "@" + configuration.getTenant()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            consumer.start(this::handle); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (IOException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.error(e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    protected void finalize() throws Throwable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        consumer.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        super.finalize(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    private static final Logger logger = LogManager.getLogger(ShellService.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    private ZbusBroker zbusBroker; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    private Consumer consumer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    private AgentConfiguration configuration; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    private CamelContext camelContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    public void setZbusBroker(ZbusBroker zbusBroker) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        this.zbusBroker = zbusBroker; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    public void setConfiguration(AgentConfiguration configuration) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        this.configuration = configuration; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    public void setCamelContext(CamelContext camelContext) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        this.camelContext = camelContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    public void handle(Message message, Consumer consumer) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        Map<String, Object> header = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        header.put("event", message.getHead("event")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        ProducerTemplate producerTemplate = camelContext.createProducerTemplate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        producerTemplate.sendBodyAndHeaders(ShellConstant.ENDPOINT, message.getBodyString(), header); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    public void server() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        if (zbusBroker == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            logger.error("zbusBroker is null"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        consumer = new Consumer(zbusBroker, ShellConstant.PREFIX_IN + "@" + configuration.getTenant()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            consumer.start(this::handle); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        } catch (IOException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            logger.error(e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    protected void finalize() throws Throwable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        consumer.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        super.finalize(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |