forked from johnlawrenceaspden/hobby-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Send.java
32 lines (28 loc) · 1.1 KB
/
Send.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
public class Send {
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!'");
chan.close();
conn.close();
}
}
// <dependency>
// <groupId>com.rabbitmq</groupId>
// <artifactId>amqp-client</artifactId>
// <version>2.2.0</version>
// </dependency>
/* Compile with:
$ javac -cp /home/john/.m2/repository/com/rabbitmq/amqp-client/2.2.0/amqp-client-2.2.0.jar Recv.java
Run with:
$ java -cp '.:/home/john/.m2/repository/com/rabbitmq/amqp-client/2.2.0/amqp-client-2.2.0.jar:/home/john/.m2/repository/commons-io/commons-io/1.4/commons-io-1.4.jar' Recv
*/