ServiceFlowEventRouter.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package com.yihu.hos.arbiter.routers;
  2. import com.yihu.hos.arbiter.configuration.ActivemqConfiguration;
  3. import com.yihu.hos.web.framework.constant.ServiceFlowConstant;
  4. import org.apache.activemq.ActiveMQConnectionFactory;
  5. import org.apache.camel.builder.RouteBuilder;
  6. import org.apache.camel.component.jms.JmsComponent;
  7. import org.apache.camel.model.ModelCamelContext;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Component;
  10. import javax.jms.ConnectionFactory;
  11. /**
  12. * @created Airhead 2016/8/1.
  13. */
  14. @Component
  15. public class ServiceFlowEventRouter extends RouteBuilder {
  16. @Autowired
  17. private ActivemqConfiguration activemqConfiguration;
  18. @Override
  19. public void configure() throws Exception {
  20. ModelCamelContext context = this.getContext();
  21. ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
  22. activemqConfiguration.getUser(), activemqConfiguration.getPassword(), activemqConfiguration.getBrokerURL());
  23. // Note we can explicit name the component
  24. context.addComponent(ServiceFlowConstant.CAMEL_COMPONENT, JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
  25. from(ServiceFlowConstant.CAMEL_ENDPOINT)
  26. .choice()
  27. // .when(header("tenant").isNotNull()).to("bean:serviceFlowService?method=handleServiceFlow")
  28. .when(header("event").isEqualTo(ServiceFlowConstant.SERVICE_FLOW_STARTED)).to("bean:serviceFlowService?method=serviceFlowStarted")
  29. .when(header("event").isEqualTo(ServiceFlowConstant.SERVICE_FLOW_STOPPED)).to("bean:serviceFlowService?method=serviceFlowStopped")
  30. .when(header("event").isEqualTo(ServiceFlowConstant.SERVICE_FLOW_ADDED)).to("bean:serviceFlowService?method=serviceFlowAdd")
  31. .when(header("event").isEqualTo(ServiceFlowConstant.SERVICE_FLOW_MODIFIED_ADD)).to("bean:serviceFlowService?method=serviceFlowModifyAdd")
  32. .when(header("event").isEqualTo(ServiceFlowConstant.SERVICE_FLOW_MODIFIED_REDUCE)).to("bean:serviceFlowService?method=serviceFlowModifyReduce")
  33. .when(header("event").isEqualTo(ServiceFlowConstant.SERVICE_FLOW_DELETED)).to("bean:serviceFlowService?method=serviceFlowDelete")
  34. .when(header("event").isEqualTo(ServiceFlowConstant.BROKER_SERVER_ON)).to("bean:serviceFlowService?method=brokerServerOn")
  35. .when(header("event").isEqualTo(ServiceFlowConstant.BROKER_SERVER_OFF)).to("bean:serviceFlowService?method=brokerServerOff")
  36. .endChoice();
  37. }
  38. }