|
4 | 4 | import com.rabbitmq.client.QueueingConsumer; |
5 | 5 |
|
6 | 6 | public class Recv { |
7 | | - public static void main(String[] argv) { |
8 | | - try { |
9 | | - Connection conn = null; |
10 | | - try { |
11 | | - ConnectionFactory factory = new ConnectionFactory(); |
12 | | - factory.setHost("localhost"); |
13 | | - conn = factory.newConnection(); |
14 | | - Channel chan = conn.createChannel(); |
15 | | - chan.queueDeclare("hello", false, false, false, null); |
| 7 | + public static void main(String[] argv) |
| 8 | + throws java.io.IOException, |
| 9 | + java.lang.InterruptedException { |
| 10 | + Connection conn = null; |
| 11 | + ConnectionFactory factory = new ConnectionFactory(); |
| 12 | + factory.setHost("localhost"); |
| 13 | + conn = factory.newConnection(); |
| 14 | + Channel chan = conn.createChannel(); |
16 | 15 |
|
17 | | - System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); |
18 | | - QueueingConsumer consumer = new QueueingConsumer(chan); |
19 | | - chan.basicConsume("hello", true, consumer); |
20 | | - while (true) { |
21 | | - QueueingConsumer.Delivery delivery = consumer.nextDelivery(); |
22 | | - System.out.println(" [x] Received " + new String(delivery.getBody())); |
23 | | - } |
24 | | - } |
25 | | - finally { |
26 | | - if (conn != null) conn.close(); |
27 | | - } |
28 | | - } |
29 | | - catch (Exception e) { |
30 | | - System.err.println("Exception while consuming"); |
31 | | - e.printStackTrace(); |
| 16 | + chan.queueDeclare("hello", false, false, false, null); |
| 17 | + |
| 18 | + System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); |
| 19 | + QueueingConsumer consumer = new QueueingConsumer(chan); |
| 20 | + chan.basicConsume("hello", true, consumer); |
| 21 | + while (true) { |
| 22 | + QueueingConsumer.Delivery delivery = consumer.nextDelivery(); |
| 23 | + System.out.println(" [x] Received " + new String(delivery.getBody())); |
32 | 24 | } |
33 | 25 | } |
34 | 26 | } |
0 commit comments