blob: b16a7fa7c364f74289394edbb3021b6c2303215d (
plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package org.apache.qpid.example.amqpexample.direct;
import org.apache.qpid.nclient.Client;
import org.apache.qpid.nclient.Connection;
import org.apache.qpid.nclient.Session;
/**
* This creates a queue a queue and binds it to the
* amq.direct exchange
*
*/
public class DeclareQueue
{
public static void main(String[] args)
{
// Create connection
Connection con = Client.createConnection();
try
{
con.connect("localhost", 5672, "test", "guest", "guest");
}
catch(Exception e)
{
System.out.print("Error connecting to broker");
e.printStackTrace();
}
// Create session
Session session = con.createSession(0);
// declare and bind queue
session.queueDeclare("message_queue", null, null);
session.exchangeBind("message_queue", "amq.direct", "routing_key", null);
// confirm completion
session.sync();
//cleanup
session.sessionDetach(session.getName());
try
{
con.close();
}
catch(Exception e)
{
System.out.print("Error closing broker connection");
e.printStackTrace();
}
}
}
|