1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System;
- using Amqp;
- using Amqp.Framing;
- using Amqp.Sasl;
- using Amqp.Types;
- namespace receive
- {
- class Program
- {
- static void Main(string[] args)
- {
- string url = "amqp://localhost:61616";
- string addr = "sampleTopic";
- bool durable = false;
- string cid = "";
- if (args.Length > 0) {
- durable = bool.Parse(args[0]);
- }
- if (durable && args.Length > 1) {
- cid = args[1];
- } else if (durable) {
- cid = Guid.NewGuid().ToString();
- }
- Address a = new Address(url);
- Connection c;
- if (durable) {
- c = new Connection(a, SaslProfile.Anonymous,
- new Open() { ContainerId = cid },
- null);
- } else {
- c = new Connection(a);
- }
- Console.WriteLine("Created new " + (durable ? "" : "non-") + "durable subscriber" + (durable ? " with ID " + cid : ""));
- Session s = new Session(c);
- ReceiverLink rl;
- if (durable) {
- Source src = new Source() {
- Address = addr,
- Durable = 2,
- ExpiryPolicy = new Symbol("never"),
- };
- rl = new ReceiverLink(s, "receiver", src, null);
- } else {
- rl = new ReceiverLink(s, "receiver", addr);
- }
- Console.WriteLine("Receiving random metrics from " + url + "/" + addr);
- while (true) {
- Message m = rl.Receive();
- rl.Accept(m);
- if (m != null) {
- Console.WriteLine("Got: " + m.Body.ToString());
- continue;
- }
- System.Threading.Thread.Sleep(1000);
- }
- }
- }
- }
|