2011-03-28 6 views
0

이것은 내 코드이며, autoDelete와 autoDelete 모두에 대해 true로 설정합니다. 교환은 마침내 소비자에게 자동으로 소비자 측에 메시지를 보내지 않습니다. 어쩌면 당신은 내 문장을 완벽하게 이해하지 못할 수도 있습니다.RABBITMQ에서 소비자 측의 시간을 설정하는 방법

어떻게 설정 할 수 있습니다 ^^ 그

과 어떻게 서버 측의 문서 개체 (문서)를받을 수 있나요

public void initConsumer() { 
    try { 
    ConnectionFactory factory = new ConnectionFactory(); 
    Connection connection = factory.newConnection(); 
    Channel channel = connection.createChannel(); 
    channel.queueDeclare(this.queueName, this.maintain, false, this.queueAutoDelete, null); 
    channel.exchangeDeclare(this.exchangeName, this.exchangeType, this.maintain, this.exchangeAutoDelete, null); 
    channel.queueBind(this.queueName, this.exchangeName, this.routingKey); 
    QueueingConsumer consumer = new QueueingConsumer(channel); 
    channel.basicConsume(this.queueName, false, consumer); 
    while (true) { 

    QueueingConsumer.Delivery delivery = consumer.nextDelivery(); 

    System.out.println(" [x] Received " 
     + new String(delivery.getBody())); 

    channel 
     .basicAck(delivery.getEnvelope().getDeliveryTag(), 
     false); 
    } 
    } catch (Exception e) { 
    System.out.println("Exception error at initConsumer()"); 
    } 
} 
+0

나는 몇 분 안에 브로커로부터 메시지를받지 못하면 어떻게 자동으로 내 컴퓨터를 종료 할 수 있습니까? 그 맞습니까? –

+0

예는 브로커로부터 메시지를 수신하지 않습니다. 그 때 – BillyLee

+0

나는 comsumer 측면을 중지하고 싶습니다. 시간을 설정하십시오. – BillyLee

답변

5

할 수 있습니다 시간 제한 매개 변수가있는) nextDelivery (의 오버로드 된 버전을 사용 :

QueueingConsumer.Delivery delivery = null; 
long timeout = 2 * 60 * 1000; // 2 minutes in milliseconds 
delivery = queuingConsumer.nextDelivery(timeout); 
if (delivery == null) { 
    // shut down your consumer here - no events arrived 
    // before the timeout was reached 
} 
else { 
    // process the delivered message here 
} 

희망이 있습니다.

+0

정말 고마워요. 제 대답을 용서해주세요. – BillyLee

+0

문제 없습니다. 대답이 맞는다면 답을 받아들이십시오. –

+0

@BrianKelly : 타임 아웃을 0으로 설정하면 대기없이 수신을 의미합니까? –

관련 문제