123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package com.yihu.hos.arbiter.routers;
- import com.yihu.hos.arbiter.configuration.ActivemqConfiguration;
- import com.yihu.hos.web.framework.constant.ServiceFlowConstant;
- import org.apache.activemq.ActiveMQConnectionFactory;
- import org.apache.camel.builder.RouteBuilder;
- import org.apache.camel.component.jms.JmsComponent;
- import org.apache.camel.model.ModelCamelContext;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import javax.jms.ConnectionFactory;
- /**
- * @created Airhead 2016/8/1.
- */
- @Component
- public class ServiceFlowEventRouter extends RouteBuilder {
- @Autowired
- private ActivemqConfiguration activemqConfiguration;
- @Override
- public void configure() throws Exception {
- ModelCamelContext context = this.getContext();
- ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
- activemqConfiguration.getUser(), activemqConfiguration.getPassword(), activemqConfiguration.getBrokerURL());
- // Note we can explicit name the component
- context.addComponent(ServiceFlowConstant.CAMEL_COMPONENT, JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
- from(ServiceFlowConstant.CAMEL_ENDPOINT)
- .choice()
- // .when(header("tenant").isNotNull()).to("bean:serviceFlowService?method=handleServiceFlow")
- .when(header("event").isEqualTo(ServiceFlowConstant.SERVICE_FLOW_STARTED)).to("bean:serviceFlowService?method=serviceFlowStarted")
- .when(header("event").isEqualTo(ServiceFlowConstant.SERVICE_FLOW_STOPPED)).to("bean:serviceFlowService?method=serviceFlowStopped")
- .when(header("event").isEqualTo(ServiceFlowConstant.SERVICE_FLOW_ADDED)).to("bean:serviceFlowService?method=serviceFlowAdd")
- .when(header("event").isEqualTo(ServiceFlowConstant.SERVICE_FLOW_MODIFIED_ADD)).to("bean:serviceFlowService?method=serviceFlowModifyAdd")
- .when(header("event").isEqualTo(ServiceFlowConstant.SERVICE_FLOW_MODIFIED_REDUCE)).to("bean:serviceFlowService?method=serviceFlowModifyReduce")
- .when(header("event").isEqualTo(ServiceFlowConstant.SERVICE_FLOW_DELETED)).to("bean:serviceFlowService?method=serviceFlowDelete")
- .when(header("event").isEqualTo(ServiceFlowConstant.BROKER_SERVER_ON)).to("bean:serviceFlowService?method=brokerServerOn")
- .when(header("event").isEqualTo(ServiceFlowConstant.BROKER_SERVER_OFF)).to("bean:serviceFlowService?method=brokerServerOff")
- .endChoice();
- }
- }
|