/*
* Copyright 2011 Kenshoo.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/  
package com.kenshoo.flume.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: sagyr
 * Date: 7/5/11
 * Time: 7:12 PM
 */
public class SimpleRabbitMqProducer implements QueuePublisher {
    private ConnectionFactory factory;
    private Connection conn;
    private Channel channel;
    public static final String EXCHANGE_NAME = "app.tracking.exchange";
    private static final Logger logger = LoggerFactory.getLogger(SimpleRabbitMqProducer.class);

    public SimpleRabbitMqProducer(String host, String userName, String password, String virtualHost) {
        factory = new ConnectionFactory();
        factory.setUsername(userName);
        factory.setPassword(password);
        factory.setVirtualHost(virtualHost);
        factory.setHost(host);
        factory.setPort(5672);
    }

    public void open() throws IOException {
        conn = factory.newConnection();
        channel = conn.createChannel();
        logger.debug("channel created successfully");
    }

    public void close() throws IOException {
        channel.close();
        conn.close();
    }

    public void publish(String routingKey, byte[] msg) throws IOException {
        channel.basicPublish(EXCHANGE_NAME, routingKey, MessageProperties.TEXT_PLAIN, msg);
        logger.debug ("published successfully with key: {}",routingKey );
    }
}

@@ -640,146 +640,9 @@
 ent.
-Channel;%0Aimport com.rabbitmq.client.Connection;%0Aimport com.rabbitmq.client.ConnectionFactory;%0Aimport com.rabbitmq.client.MessageProperties
+*
 ;%0Aim
@@ -1139,16 +1139,42 @@
 .class);
+%0A    private String hosts;
 %0A%0A    pu
@@ -1212,16 +1212,17 @@
 ing host
+s
 , String
@@ -1441,39 +1441,8 @@
 t);%0A
-        factory.setHost(host);%0A
     
@@ -1468,16 +1468,44 @@
 (5672);%0A
+        this.hosts = hosts;%0A
     %7D%0A%0A 
@@ -1584,16 +1584,45 @@
 nection(
+Address.parseAddresses(hosts)
 );%0A     

support multiple hosts for rabbit settings