Skip to content

Commit 6190671

Browse files
author
Ann
committed
connection, channel, explicit parameters
1 parent b579201 commit 6190671

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

java/NewTask.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@
44
import com.rabbitmq.client.MessageProperties;
55

66
public class NewTask {
7-
public static void main(String[] argv)
8-
throws java.io.IOException {
9-
Connection conn = null;
10-
ConnectionFactory factory = new ConnectionFactory();
11-
factory.setHost("localhost");
12-
conn = factory.newConnection();
13-
Channel chan = conn.createChannel();
7+
public static void main(String[] argv) throws java.io.IOException {
8+
Connection connection = null;
9+
ConnectionFactory factory = new ConnectionFactory();
10+
factory.setHost("localhost");
11+
connection = factory.newConnection();
12+
Channel channel = connection.createChannel();
1413

15-
// make durable
16-
chan.queueDeclare("task_queue", true, false, false, null);
14+
boolean durable = true;
15+
channel.queueDeclare("task_queue", durable, false, false, null);
1716

18-
String message = joinStrings(argv);
19-
if (message == "") message = "Hello World!";
17+
String message = joinStrings(argv);
18+
if (message == "") message = "Hello World!";
2019

21-
// make persistent
22-
chan.basicPublish("", "task_queue", MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
23-
System.out.println(" [x] Sent '" + message + "'");
24-
chan.close();
25-
conn.close();
26-
}
20+
// make message props persistent
21+
channel.basicPublish( "", "task_queue",
22+
MessageProperties.PERSISTENT_TEXT_PLAIN,
23+
message.getBytes());
24+
System.out.println(" [x] Sent '" + message + "'");
25+
channel.close();
26+
connection.close();
27+
}
2728

2829
private static String joinStrings(String[] strings){
2930
String words = "";

0 commit comments

Comments
 (0)