package com.yihu.hos.arbiter.routers;

import com.yihu.hos.arbiter.configuration.ActivemqConfiguration;
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 EndpointEventRouter 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("endpoint.event", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
        from("endpoint.event:queue:configuration.endpoint")
                .to("bean:endpointService?method=trigger"); //TODO:这边可以做Message Filter，减化trigger逻辑
    }
}
