|  | @ -1,20 +1,11 @@
 | 
												
													
														
															|  | package com.yihu.hos.agent.service;
 |  | package com.yihu.hos.agent.service;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | import com.yihu.hos.agent.configuration.AgentConfiguration;
 |  | import com.yihu.hos.agent.configuration.AgentConfiguration;
 | 
												
													
														
															|  | import com.yihu.hos.agent.constant.FlowConstant;
 |  | 
 | 
												
													
														
															|  | import org.apache.camel.CamelContext;
 |  | import org.apache.camel.CamelContext;
 | 
												
													
														
															|  | import org.apache.camel.ProducerTemplate;
 |  | 
 | 
												
													
														
															|  | import org.apache.log4j.LogManager;
 |  | import org.apache.log4j.LogManager;
 | 
												
													
														
															|  | import org.apache.log4j.Logger;
 |  | import org.apache.log4j.Logger;
 | 
												
													
														
															|  | import org.springframework.beans.factory.annotation.Autowired;
 |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
												
													
														
															|  | import org.springframework.stereotype.Service;
 |  | 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 Airhead
 |  |  * @author Airhead
 | 
												
											
												
													
														
															|  | @ -24,15 +15,15 @@ import java.util.Map;
 | 
												
													
														
															|  | public class FlowService {
 |  | public class FlowService {
 | 
												
													
														
															|  |     private static final Logger logger = LogManager.getLogger(ShellService.class);
 |  |     private static final Logger logger = LogManager.getLogger(ShellService.class);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     private ZbusBroker zbusBroker;
 |  | 
 | 
												
													
														
															|  |     private Consumer consumer;
 |  | 
 | 
												
													
														
															|  | 
 |  | //    private ZbusBroker zbusBroker;
 | 
												
													
														
															|  | 
 |  | //    private Consumer consumer;
 | 
												
													
														
															|  |     private AgentConfiguration configuration;
 |  |     private AgentConfiguration configuration;
 | 
												
													
														
															|  |     private CamelContext camelContext;
 |  |     private CamelContext camelContext;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     @Autowired
 |  | 
 | 
												
													
														
															|  |     public void setZbusBroker(ZbusBroker zbusBroker) {
 |  | 
 | 
												
													
														
															|  |         this.zbusBroker = zbusBroker;
 |  | 
 | 
												
													
														
															|  |     }
 |  | 
 | 
												
													
														
															|  | 
 |  | //    @Autowired
 | 
												
													
														
															|  | 
 |  | //    public void setZbusBroker(ZbusBroker zbusBroker) {
 | 
												
													
														
															|  | 
 |  | //        this.zbusBroker = zbusBroker;
 | 
												
													
														
															|  | 
 |  | //    }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     public void setConfiguration(AgentConfiguration configuration) {
 |  |     public void setConfiguration(AgentConfiguration configuration) {
 | 
												
											
												
													
														
															|  | @ -44,32 +35,32 @@ public class FlowService {
 | 
												
													
														
															|  |         this.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(FlowConstant.ENDPOINT, message.getBodyString(), header);
 |  | 
 | 
												
													
														
															|  |     }
 |  | 
 | 
												
													
														
															|  | 
 |  | //    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(FlowConstant.ENDPOINT, message.getBodyString(), header);
 | 
												
													
														
															|  | 
 |  | //    }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     public void server() {
 |  | 
 | 
												
													
														
															|  |         if (zbusBroker == null) {
 |  | 
 | 
												
													
														
															|  |             logger.error("zbusBroker is null");
 |  | 
 | 
												
													
														
															|  |             return;
 |  | 
 | 
												
													
														
															|  |         }
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         consumer = new Consumer(zbusBroker, FlowConstant.PREFIX + "@" + 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();
 |  | 
 | 
												
													
														
															|  |     }
 |  | 
 | 
												
													
														
															|  | 
 |  | //    public void server() {
 | 
												
													
														
															|  | 
 |  | //        if (zbusBroker == null) {
 | 
												
													
														
															|  | 
 |  | //            logger.error("zbusBroker is null");
 | 
												
													
														
															|  | 
 |  | //            return;
 | 
												
													
														
															|  | 
 |  | //        }
 | 
												
													
														
															|  | 
 |  | //
 | 
												
													
														
															|  | 
 |  | //        consumer = new Consumer(zbusBroker, FlowConstant.PREFIX + "@" + 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();
 | 
												
													
														
															|  | 
 |  | //    }
 | 
												
													
														
															|  | }
 |  | }
 |