Skip to content

Commit

Permalink
Don't handle exceptions in java example
Browse files Browse the repository at this point in the history
  • Loading branch information
majek committed Dec 13, 2010
1 parent b6778b3 commit 0cd19cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 44 deletions.
40 changes: 16 additions & 24 deletions java/Recv.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,23 @@
import com.rabbitmq.client.QueueingConsumer;

public class Recv {
public static void main(String[] argv) {
try {
Connection conn = null;
try {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
conn = factory.newConnection();
Channel chan = conn.createChannel();
chan.queueDeclare("hello", false, false, false, null);
public static void main(String[] argv)
throws java.io.IOException,
java.lang.InterruptedException {
Connection conn = null;
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
conn = factory.newConnection();
Channel chan = conn.createChannel();

System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
QueueingConsumer consumer = new QueueingConsumer(chan);
chan.basicConsume("hello", true, consumer);
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
System.out.println(" [x] Received " + new String(delivery.getBody()));
}
}
finally {
if (conn != null) conn.close();
}
}
catch (Exception e) {
System.err.println("Exception while consuming");
e.printStackTrace();
chan.queueDeclare("hello", false, false, false, null);

System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
QueueingConsumer consumer = new QueueingConsumer(chan);
chan.basicConsume("hello", true, consumer);
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
System.out.println(" [x] Received " + new String(delivery.getBody()));
}
}
}
31 changes: 11 additions & 20 deletions java/Send.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,16 @@
import java.io.IOException;

public class Send {
public static void main(String[] argv) {
try {
Connection conn = null;
try {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
conn = factory.newConnection();
Channel chan = conn.createChannel();
chan.queueDeclare("hello", false, false, false, null);
chan.basicPublish("", "hello", null, "Hello World!".getBytes());
System.out.println(" [x] Sent 'Hello World!'");
}
finally {
if (conn != null) conn.close();
}
}
catch (Exception e) {
System.err.println("Exception while publishing");
e.printStackTrace();
}
public static void main(String[] argv)
throws java.io.IOException {
Connection conn = null;
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
conn = factory.newConnection();
Channel chan = conn.createChannel();
chan.queueDeclare("hello", false, false, false, null);
chan.basicPublish("", "hello", null, "Hello World!".getBytes());
System.out.println(" [x] Sent 'Hello World!'");
conn.close();
}
}

0 comments on commit 0cd19cb

Please sign in to comment.