132
|
1 private import tango.core.Thread;
|
|
2
|
|
3 private import tango.util.log.Configurator;
|
|
4
|
|
5 private import tango.net.cluster.NetworkQueue;
|
|
6
|
|
7 private import tango.net.cluster.tina.Cluster;
|
|
8
|
|
9 /*******************************************************************************
|
|
10
|
|
11 Illustrates how to setup and use a Queue in asynchronous mode
|
|
12
|
|
13 *******************************************************************************/
|
|
14
|
|
15 void main ()
|
|
16 {
|
|
17 void listen (IEvent event)
|
|
18 {
|
|
19 while (event.get)
|
|
20 event.log.info ("received asynch msg on channel " ~ event.channel.name);
|
|
21 }
|
|
22
|
|
23
|
|
24 // join the cluster
|
|
25 auto cluster = (new Cluster).join;
|
|
26
|
|
27 // access a queue of the specified name
|
|
28 auto queue = new NetworkQueue (cluster, "my.queue.channel");
|
|
29
|
|
30 // listen for messages placed in my queue, via a delegate
|
|
31 queue.createConsumer (&listen);
|
|
32
|
|
33 // stuff something into the queue
|
|
34 queue.log.info ("sending three messages to the queue");
|
|
35 queue.put (queue.EmptyMessage);
|
|
36 queue.put (queue.EmptyMessage);
|
|
37 queue.put (queue.EmptyMessage);
|
|
38
|
|
39 // wait for asynchronous msgs to arrive ...
|
|
40 Thread.sleep (1);
|
|
41 }
|