浏览代码

路由编排调试

lingfeng 8 年之前
父节点
当前提交
7c69a7234a

+ 10 - 0
hos-broker/src/main/java/com/yihu/hos/common/listener/ApplicationStartListener.java

@ -1,5 +1,6 @@
package com.yihu.hos.common.listener;
import com.yihu.hos.common.configuration.ActivemqConfiguration;
import com.yihu.hos.common.constants.Constant;
import com.yihu.hos.common.dao.BrokerDao;
import com.yihu.hos.core.datatype.ClassFileUtil;
@ -8,12 +9,15 @@ import com.yihu.hos.models.SystemCamelContext;
import com.yihu.hos.models.SystemClassMapping;
import com.yihu.hos.models.SystemServiceFlow;
import com.yihu.hos.models.SystemServiceFlowClass;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import javax.jms.ConnectionFactory;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
@ -106,6 +110,12 @@ public class ApplicationStartListener implements ApplicationListener<ContextRefr
        // 4、=============
        // 首先启动Apache Camel服务
        SystemCamelContext.getDefaultCamelContext().start();
        ActivemqConfiguration activemqConfiguration = contextRefreshedEvent.getApplicationContext().getBean(ActivemqConfiguration.class);
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
                activemqConfiguration.getUser(), activemqConfiguration.getPassword(), activemqConfiguration.getBrokerURL());
        // Note we can explicit name the component
        SystemCamelContext.getDefaultCamelContext().addComponent("business-log", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
        logger.info("Apache Camel Context 启动完成......");
        // 加载和设置ClassLoader
        List<URL> URLs = new ArrayList<>();

+ 18 - 0
hos-broker/src/main/java/com/yihu/hos/controllers/ESBCamelController.java

@ -100,4 +100,22 @@ public class ESBCamelController {
            @RequestParam(value = "className") String className) {
        return esbCamelService.onRouteDefineDelete(serviceFlow, packageName, className);
    }
    @RequestMapping(value = "/route/start", produces = "application/json;charset=UTF-8", method = RequestMethod.PUT)
    @ResponseBody
    @ApiOperation(value = "删除Route路由", produces = "application/json", notes = "启动路由时,该事件被触发")
    public Result onRouteDefineStart(
            @ApiParam(name = "serviceFlow", value = "服务名称", required = true)
            @RequestParam(value = "serviceFlow") String serviceFlow) {
        return esbCamelService.onRouteDefineStart(serviceFlow);
    }
    @RequestMapping(value = "/route/stop", produces = "application/json;charset=UTF-8", method = RequestMethod.PUT)
    @ResponseBody
    @ApiOperation(value = "删除Route路由", produces = "application/json", notes = "停止路由时,该事件被触发")
    public Result onRouteDefineStop(
            @ApiParam(name = "serviceFlow", value = "服务名称", required = true)
            @RequestParam(value = "serviceFlow") String serviceFlow) {
        return esbCamelService.onRouteDefineStop(serviceFlow);
    }
}

+ 36 - 0
hos-broker/src/main/java/com/yihu/hos/services/ESBCamelService.java

@ -152,6 +152,42 @@ public class ESBCamelService {
        }
    }
    /**
     * 启动路由时,该事件被触发。
     */
    public Result onRouteDefineStart(String serviceFlow) {
        try {
            if(StringUtil.isEmpty(serviceFlow)) {
                logger.error("必要的入参数据不正确,请检查!");
                return Result.error("必要的入参数据不正确,请检查!");
            }
            SystemCamelContext.getDefaultCamelContext().startRoute(serviceFlow);
            return Result.success("启动路由成功!");
        } catch (Exception e) {
            return Result.error("启动路由失败!");
        }
    }
    /**
     * 停止路由时,该事件被触发。
     */
    public Result onRouteDefineStop(String serviceFlow) {
        try {
            if(StringUtil.isEmpty(serviceFlow)) {
                logger.error("必要的入参数据不正确,请检查!");
                return Result.error("必要的入参数据不正确,请检查!");
            }
            SystemCamelContext.getDefaultCamelContext().stopRoute(serviceFlow);
            return Result.success("停止路由成功!");
        } catch (Exception e) {
            return Result.error("停止路由失败!");
        }
    }
    private void createClassfile(String serviceFlow, String packageName, String className, String path, String type) throws MalformedURLException {
        // 1、============