// Path: netty-http/src/main/java/http/Config.java
// public class Config {
//     public Integer getBacklog() {
//         return 1280;
//     }
// 
//     public Integer getPort() {
//         return 9999;
//     }
// 
//     public Integer getClientMaxBodySize() {
//         return 1024*1024*10;
//     }
// 
//     public Integer getTaskThreadPoolSize() {
//         return 0;
//     }
// 
//     public Integer getEventLoopThreadCount() {
//         return 10;
//     }
// }
// 
// Path: rabbitmqservice/src/main/java/rabbitmq/ListenerJobBuilder.java
// public class ListenerJobBuilder {
//     // just everything under default
//     public static MQListenerAdmin buildMQListenerAdmin(ConfigurableApplicationContext context) {
//         MessageListenerProxy listenerProxy = new MessageListenerProxy(new ESMessageListener(context),
//                 "Elastic_Queue");
//         return new MQListenerAdmin(getConnectionFactory(), listenerProxy);
//     }
// 
//     public static ConnectionFactory getConnectionFactory() {
//         CachingConnectionFactory connectionFactory = new CachingConnectionFactory("10.128.165.206");
//         connectionFactory.setUsername("guest");
//         connectionFactory.setPassword("guest");
//         return connectionFactory;
//     }
// }
// 
// Path: rabbitmqservice/src/main/java/rabbitmq/MQListenerAdmin.java
// public class MQListenerAdmin {
//     private static final Logger logger = Logger.getLogger(MQListenerAdmin.class);
//     private final ConnectionFactory mqFactory;;
//     private final RabbitAdmin amqpAdmin;
//     private final SimpleMessageListenerContainer container;
//     private Boolean startSucceeded = false;
//     private Queue queue;
//     private final MessageListener listener;
// 
//     public MQListenerAdmin(ConnectionFactory mqFactory, MessageListener listener) {
//         container = new SimpleMessageListenerContainer();
//         this.mqFactory = mqFactory;
//         amqpAdmin = new RabbitAdmin(mqFactory);
//         this.listener = listener;
//     }
// 
//     public void start() {
//         declareQueue();
// 
//         container.setAcknowledgeMode(AcknowledgeMode.AUTO);
//         container.setAutoStartup(false);
//         container.setChannelTransacted(false);
//         container.setConcurrentConsumers(MQParsedConfig.conncurrentConsumers);
//         container.setConnectionFactory(mqFactory);
//         container.setPrefetchCount(1);
//         container.setQueueNames(queue.getName());
//         // container.setTransactionManager(new
//         // RabbitTransactionManager(mqFactory));
//         container.setMessageListener(listener);
//         container.setDefaultRequeueRejected(true);
//         container.start();
//         startSucceeded = true;
//     }
// 
//     private void declareQueue() {
//         amqpAdmin.declareExchange(new TopicExchange(MQParsedConfig.exchangeName));
//         queue = new Queue("ElasticRabbit");
//         amqpAdmin.declareQueue(queue);
// 
//         logger.info("Using queue name:" + queue.getName());
// 
//         String[] routingKeys = MQParsedConfig.routingKeys;
//         for (String routingKey : routingKeys) {
//             amqpAdmin.declareBinding(new Binding(queue.getName(),
//                     Binding.DestinationType.QUEUE, MQParsedConfig.exchangeName, routingKey, null));
//         }
//     }
// 
// }


import http.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.Banner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import rabbitmq.ListenerJobBuilder;
import rabbitmq.MQListenerAdmin;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReadWriteLock;



/**
 * Created by I311352 on 12/28/2016.
 */
@SpringBootConfiguration
@EnableAutoConfiguration
@EnableHystrix
@EnableCircuitBreaker
@EnableHystrixDashboard
@ComponentScan({ "elasticsearch","rabbitmq", "sync"})
public class ElasticRabbitApp implements CommandLineRunner {
    @Autowired
    private ConfigurableApplicationContext context;

    public static void main(String[] args) {
        SpringApplication.run(ElasticRabbitApp.class, args);
    }

    @Override
    public void run(String... args) throws Exception {

// Path: netty-http/src/main/java/http/Config.java
// public class Config {
//     public Integer getBacklog() {
//         return 1280;
//     }
// 
//     public Integer getPort() {
//         return 9999;
//     }
// 
//     public Integer getClientMaxBodySize() {
//         return 1024*1024*10;
//     }
// 
//     public Integer getTaskThreadPoolSize() {
//         return 0;
//     }
// 
//     public Integer getEventLoopThreadCount() {
//         return 10;
//     }
// }
// 
// Path: rabbitmqservice/src/main/java/rabbitmq/ListenerJobBuilder.java
// public class ListenerJobBuilder {
//     // just everything under default
//     public static MQListenerAdmin buildMQListenerAdmin(ConfigurableApplicationContext context) {
//         MessageListenerProxy listenerProxy = new MessageListenerProxy(new ESMessageListener(context),
//                 "Elastic_Queue");
//         return new MQListenerAdmin(getConnectionFactory(), listenerProxy);
//     }
// 
//     public static ConnectionFactory getConnectionFactory() {
//         CachingConnectionFactory connectionFactory = new CachingConnectionFactory("10.128.165.206");
//         connectionFactory.setUsername("guest");
//         connectionFactory.setPassword("guest");
//         return connectionFactory;
//     }
// }
// 
// Path: rabbitmqservice/src/main/java/rabbitmq/MQListenerAdmin.java
// public class MQListenerAdmin {
//     private static final Logger logger = Logger.getLogger(MQListenerAdmin.class);
//     private final ConnectionFactory mqFactory;;
//     private final RabbitAdmin amqpAdmin;
//     private final SimpleMessageListenerContainer container;
//     private Boolean startSucceeded = false;
//     private Queue queue;
//     private final MessageListener listener;
// 
//     public MQListenerAdmin(ConnectionFactory mqFactory, MessageListener listener) {
//         container = new SimpleMessageListenerContainer();
//         this.mqFactory = mqFactory;
//         amqpAdmin = new RabbitAdmin(mqFactory);
//         this.listener = listener;
//     }
// 
//     public void start() {
//         declareQueue();
// 
//         container.setAcknowledgeMode(AcknowledgeMode.AUTO);
//         container.setAutoStartup(false);
//         container.setChannelTransacted(false);
//         container.setConcurrentConsumers(MQParsedConfig.conncurrentConsumers);
//         container.setConnectionFactory(mqFactory);
//         container.setPrefetchCount(1);
//         container.setQueueNames(queue.getName());
//         // container.setTransactionManager(new
//         // RabbitTransactionManager(mqFactory));
//         container.setMessageListener(listener);
//         container.setDefaultRequeueRejected(true);
//         container.start();
//         startSucceeded = true;
//     }
// 
//     private void declareQueue() {
//         amqpAdmin.declareExchange(new TopicExchange(MQParsedConfig.exchangeName));
//         queue = new Queue("ElasticRabbit");
//         amqpAdmin.declareQueue(queue);
// 
//         logger.info("Using queue name:" + queue.getName());
// 
//         String[] routingKeys = MQParsedConfig.routingKeys;
//         for (String routingKey : routingKeys) {
//             amqpAdmin.declareBinding(new Binding(queue.getName(),
//                     Binding.DestinationType.QUEUE, MQParsedConfig.exchangeName, routingKey, null));
//         }
//     }
// 
// }


// Path: app/src/main/java/ElasticRabbitApp.java
import http.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.Banner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import rabbitmq.ListenerJobBuilder;
import rabbitmq.MQListenerAdmin;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReadWriteLock;



/**
 * Created by I311352 on 12/28/2016.
 */
@SpringBootConfiguration
@EnableAutoConfiguration
@EnableHystrix
@EnableCircuitBreaker
@EnableHystrixDashboard
@ComponentScan({ "elasticsearch","rabbitmq", "sync"})
public class ElasticRabbitApp implements CommandLineRunner {
    @Autowired
    private ConfigurableApplicationContext context;

    public static void main(String[] args) {
        SpringApplication.run(ElasticRabbitApp.class, args);
    }

    @Override
    public void run(String... args) throws Exception {

        MQListenerAdmin listenerAdmin = ListenerJobBuilder.buildMQListenerAdmin(context);
