Example usage for com.rabbitmq.client.impl.recovery AutorecoveringConnection createChannel

List of usage examples for com.rabbitmq.client.impl.recovery AutorecoveringConnection createChannel

Introduction

In this page you can find the example usage for com.rabbitmq.client.impl.recovery AutorecoveringConnection createChannel.

Prototype

@Override
public Channel createChannel() throws IOException 

Source Link

Usage

From source file:ylj.demo.mq.amqp.rabbitmq_client.DemoConsumer.java

License:Apache License

public static void doConsume() throws Exception {
    ExecutorService consumeES = Executors.newFixedThreadPool(2);

    ConnectionFactory factory = new ConnectionFactory();
    factory.setUri("amqp://guest:guest@newsrec10.photo.163.org:5672");
    //     factory.setUri("amqp://guest:guest@/?brokerlist='tcp://newsrec10.photo.163.org:5672'");

    factory.setAutomaticRecoveryEnabled(true);
    factory.setNetworkRecoveryInterval(10000);
    factory.setExceptionHandler(new MyExceptionHandler());

    AutorecoveringConnection conn = (AutorecoveringConnection) factory.newConnection(consumeES);
    conn.addRecoveryListener(new MyRecoveryListener());

    // ?queue??//from w ww. ja  v  a  2  s .c om
    Channel channel = conn.createChannel();
    // channel.close();

    // channel.queueDeclare("recsys.news.userfeed.usermodel", false, false, false, null);
    // channel.basicConsume("recsys.news.userfeed.usermodel", true, null, new MyConsumer());
    channel.basicConsume("recsys.news.userfeed.usermodel", new MyConsumer());

    // conn.close();

    /*
         
     * 
        work??work????
        channel.basicConsume("hello",false,consumer);   
        channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
     * 
     */
}