2017-10-25 12 views
0

com.rabbitmq.client.AlreadyClosedException : 연결 종료 정리; 이유 : 폐쇄 채널을com.rabbitmq.client.AlreadyClosedException 발생 : 연결 종료 정리;

at com.rabbitmq.client.impl.AMQ 

Channel.ensureIsOpen (AMQChannel.java:190)를 사용하려고

at com.rabbitmq.client.impl.AMQChannel.transmit(AMQChannel.java:291) 

at com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:562) 

at com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:545) 

at citylink.SearchNotification.completeTask1(SearchNotification.java:135) 

at citylink.SearchNotification.run(SearchNotification.java:80) 

at java.util.TimerThread.mainLoop(Unknown Source) 

at java.util.TimerThread.run(Unknown Source) 

답변

0

나는 사실 내가 오랫동안 내 채널이 열려 유지하고, 문제를 해결했다. 그래서 RabbitMQ는 더 이상 사용하지 않는 채널을 닫고있었습니다. 그래서 그것을 사용 후뿐만 아니라 채널과 연결을 닫습니다. 다음은 코드입니다.

try { 
     //Create the Connection 
     Connection connection = connectionFactory.newConnection(); 
     //Create the Channel 
     Channel channel = connection.createChannel();      
     QueueingConsumer consumer = new QueueingConsumer(channel); 
     channel.basicConsume(QueueName, consumer);    
     boolean removeAllUpTo = true; 
     while(true){ 
      Delivery delivery = consumer.nextDelivery(5000);    
      if(delivery == null) break; 
      if(processMessage(delivery)){ 
       long deliveryTag=delivery.getEnvelope().getDeliveryTag(); 
       channel.basicAck(deliveryTag, removeAllUpTo); 
      } 
     }   
     channel.close(); 
     connection.close(   
    } catch (IOException e) { 
     e.printStackTrace(); 
    } catch (ShutdownSignalException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (ConsumerCancelledException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (InterruptedException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    }