1 | package omq.test.multiThread2; |
---|
2 | |
---|
3 | import java.util.Properties; |
---|
4 | |
---|
5 | import omq.common.broker.Broker; |
---|
6 | import omq.common.util.ParameterQueue; |
---|
7 | import omq.test.supervisor.Sleep; |
---|
8 | import omq.test.supervisor.SleepImpl; |
---|
9 | |
---|
10 | import org.junit.BeforeClass; |
---|
11 | import org.junit.Test; |
---|
12 | |
---|
13 | public class MultiThreadTest { |
---|
14 | @BeforeClass |
---|
15 | public static void Server() throws Exception { |
---|
16 | Properties env = new Properties(); |
---|
17 | env.setProperty(ParameterQueue.USER_NAME, "guest"); |
---|
18 | env.setProperty(ParameterQueue.USER_PASS, "guest"); |
---|
19 | |
---|
20 | // Get host info of rabbimq (where it is) |
---|
21 | env.setProperty(ParameterQueue.RABBIT_HOST, "127.0.0.1"); |
---|
22 | env.setProperty(ParameterQueue.RABBIT_PORT, "5672"); |
---|
23 | env.setProperty(ParameterQueue.NUM_THREADS, "4"); |
---|
24 | |
---|
25 | SleepImpl sleep = new SleepImpl(); |
---|
26 | |
---|
27 | Broker broker = new Broker(env); |
---|
28 | broker.bind("sleep", sleep); |
---|
29 | |
---|
30 | } |
---|
31 | |
---|
32 | @Test |
---|
33 | public void test() throws Exception { |
---|
34 | Properties env = new Properties(); |
---|
35 | env.setProperty(ParameterQueue.USER_NAME, "guest"); |
---|
36 | env.setProperty(ParameterQueue.USER_PASS, "guest"); |
---|
37 | |
---|
38 | // Get host info of rabbimq (where it is) |
---|
39 | env.setProperty(ParameterQueue.RABBIT_HOST, "127.0.0.1"); |
---|
40 | env.setProperty(ParameterQueue.RABBIT_PORT, "5672"); |
---|
41 | |
---|
42 | Broker broker = new Broker(env); |
---|
43 | Sleep sleep = broker.lookup("sleep", Sleep.class); |
---|
44 | |
---|
45 | for (int i = 0; i < 10; i++) { |
---|
46 | sleep.sleep(); |
---|
47 | } |
---|
48 | |
---|
49 | Thread.sleep(10000); |
---|
50 | } |
---|
51 | |
---|
52 | } |
---|