10000 Uppercase classes, change queue name to match diagrams, cope with fai… · rakesharya/rabbitmq-tutorials@6b2d147 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b2d147

Browse files
committed
Uppercase classes, change queue name to match diagrams, cope with failure.
1 parent 1250c23 commit 6b2d147

File tree

4 files changed

+55
-46
lines changed

4 files changed

+55
-46
lines changed

java/Recv.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import com.rabbitmq.client.ConnectionFactory;
2+
import com.rabbitmq.client.Connection;
3+
import com.rabbitmq.client.Channel;
4+
import com.rabbitmq.client.QueueingConsumer;
5+
6+
public class Recv {
7+
public static void main(String[] argv) {
8+
try {
9+
Connection conn = null;
10+
try {
11+
conn = new ConnectionFactory().newConnection();
12+
Channel chan = conn.createChannel();
13+
chan.queueDeclare("test", false, false, false, null);
14+
QueueingConsumer consumer = new QueueingConsumer(chan);
15+
chan.basicConsume("test", true, consumer);
16+
while (true) {
17+
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
18+
System.out.println(new String(delivery.getBody()));
19+
}
20+
}
21+
finally {
22+
if (conn != null) conn.close();
23+
}
24+
}
25+
catch (Exception e) {
26+
System.err.println("Exception while consuming");
27+
e.printStackTrace();
28+
}
29+
}
30+
}

java/Send.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import com.rabbitmq.client.ConnectionFactory;
2+
import com.rabbitmq.client.Connection;
3+
import com.rabbitmq.client.Channel;
4+
import java.io.IOException;
5+
6+
public class Send {
7+
public static void main(String[] argv) {
8+
try {
9+
Connection conn = null;
10+
try {
11+
conn = new ConnectionFactory().newConnection();
12+
Channel chan = conn.createChannel();
13+
chan.queueDeclare("test", false, false, false, null);
14+
chan.basicPublish("", "test", null, "Hello World!".getBytes());
15+
}
16+
finally {
17+
if (conn != null) conn.close();
18+
}
19+
}
20+
catch (Exception e) {
21+
System.err.println("Exception while publishing");
22+
e.printStackTrace();
23+
}
24+
}
25+
}

java/recv.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

java/send.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0