package com.yihu.hos.broker.common.camelrouter;

import com.yihu.hos.broker.configurations.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/8.
 */
@Component
public class BusinessLogRouter extends RouteBuilder {
    static public final String DESTINATION_NAME = "business-log";
    @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(DESTINATION_NAME, JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
        from("business-log:topic:business.log.queue")
                .to("bean:businessLogService?method=log");
    }
}
