|
4 | 4 | import com.rabbitmq.client.MessageProperties; |
5 | 5 |
|
6 | 6 | 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(); |
14 | 13 |
|
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); |
17 | 16 |
|
18 | | - String message = joinStrings(argv); |
19 | | - if (message == "") message = "Hello World!"; |
| 17 | + String message = joinStrings(argv); |
| 18 | + if (message == "") message = "Hello World!"; |
20 | 19 |
|
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 | + } |
27 | 28 |
|
28 | 29 | private static String joinStrings(String[] strings){ |
29 | 30 | String words = ""; |
|
0 commit comments