Esempio n. 1
0
        private double processRate(int size, string queue)
        {
            CircularBuffer <IMessage> buffer   = new CircularBuffer <IMessage>(100);
            IMessageListener          listener = new SyncListener(buffer);
            string localQueue = "queue-" + UUID.RandomUuid();

            Session.QueueDeclare(localQueue, null, null, Option.AUTO_DELETE);
            Session.ExchangeBind(localQueue, "amq.direct", queue);
            Session.AttachMessageListener(listener, localQueue);
            Session.MessageSubscribe(localQueue);
            double   rate  = 0;
            RangeSet range = new RangeSet();

            for (int i = 0; i < size; ++i)
            {
                IMessage m = buffer.Dequeue();
                range.Add(m.Id);
                BinaryReader reader = new BinaryReader(m.Body, Encoding.UTF8);
                byte[]       body   = new byte[m.Body.Length - m.Body.Position];
                reader.Read(body, 0, body.Length);
                rate += BitConverter.ToDouble(body, 0);
            }
            Session.MessageAccept(range);
            return(rate);
        }
Esempio n. 2
0
        public void sendAndPurge()
        {
            _log.Debug("Running: ExchangeBind");
            IClientSession ssn = Client.CreateSession(0);

            ssn.QueueDelete("queue1");
            QueueQueryResult result = (QueueQueryResult)ssn.QueueQuery("queue1").Result;

            Assert.IsNull(result.GetQueue());
            ssn.QueueDeclare("queue1", null, null);
            ssn.ExchangeBind("queue1", "amq.direct", "queue1", null);

            for (int i = 0; i < 10; i++)
            {
                ssn.MessageTransfer("amq.direct", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED,
                                    new Header(new DeliveryProperties().SetRoutingKey("queue1"),
                                               new MessageProperties().SetMessageId(UUID.RandomUuid())),
                                    Encoding.UTF8.GetBytes("test: " + i));
            }
            ssn.Sync();
            result = (QueueQueryResult)ssn.QueueQuery("queue1").Result;
            Assert.IsTrue(result.GetMessageCount() == 10);
            ssn.QueuePurge("queue1");
            ssn.Sync();
            result = (QueueQueryResult)ssn.QueueQuery("queue1").Result;
            Assert.IsTrue(result.GetMessageCount() == 0);
        }
Esempio n. 3
0
        public void two_uuid_with_same_value_should_have_same_hash_code()
        {
            UUID uuid  = UUID.RandomUuid();
            UUID uuid2 = new UUID(uuid.MostSignificantBits, uuid.LeastSignificantBits);

            Assert.AreEqual(uuid, uuid2);
            Assert.AreEqual(uuid.GetHashCode(), uuid2.GetHashCode());
        }
Esempio n. 4
0
        public void ToString_should_override_and_not_hide_base()
        {
            UUID uuid = UUID.RandomUuid();

            string uuidStr    = uuid.ToString();
            string uuidConcat = "Test." + uuid;

            Assert.AreEqual("Test." + uuidStr, uuidConcat);
        }
Esempio n. 5
0
        public IClientSession CreateSession(long expiryInSeconds)
        {
            Channel       ch  = _conn.GetChannel();
            ClientSession ssn = new ClientSession(Encoding.UTF8.GetBytes(UUID.RandomUuid().ToString()));

            ssn.Attach(ch);
            ssn.SessionAttach(ssn.GetName());
            ssn.SessionRequestTimeout(expiryInSeconds);
            return(ssn);
        }
Esempio n. 6
0
        public void createUUID()
        {
            UUID   uuid    = UUID.RandomUuid();
            String uuidStr = uuid.ToString();

            Assert.IsNotNull(uuid);
            UUID uuid2 = UUID.RandomUuid();

            Assert.AreNotSame(uuid, uuid2);
        }
 public void MessageTransfer(String destination, IMessage message)
 {
     byte[] body = new byte[message.Body.Position];
     message.Body.Seek(0, SeekOrigin.Begin);
     message.Body.Read(body, 0, body.Length);
     message.MessageProperties.SetMessageId(UUID.RandomUuid());
     MessageTransfer(destination,
                     MessageAcceptMode.NONE,
                     MessageAcquireMode.PRE_ACQUIRED,
                     message.Header,
                     body);
 }
Esempio n. 8
0
        private void sendAndReceive(byte[] messageBody, int count)
        {
            IClientSession ssn = Client.CreateSession(0);

            ssn.Sync();
            ssn.QueueDeclare("queue1", null, null);
            ssn.QueueDelete("queue1");
            QueueQueryResult result = (QueueQueryResult)ssn.QueueQuery("queue1").Result;

            Assert.IsNull(result.GetQueue());
            ssn.QueueDeclare("queue1", null, null);
            ssn.ExchangeBind("queue1", "amq.direct", "queue1", null);
            Object     myLock     = new Object();
            MyListener myListener = new MyListener(myLock, count);

            ssn.AttachMessageListener(myListener, "myDest");

            ssn.MessageSubscribe("queue1", "myDest", MessageAcceptMode.EXPLICIT, MessageAcquireMode.PRE_ACQUIRED, null,
                                 0, null);


            // issue credits
            ssn.MessageSetFlowMode("myDest", MessageFlowMode.WINDOW);
            ssn.MessageFlow("myDest", MessageCreditUnit.BYTE, ClientSession.MESSAGE_FLOW_MAX_BYTES);
            ssn.MessageFlow("myDest", MessageCreditUnit.MESSAGE, 10000);
            ssn.Sync();

            for (int i = 0; i < count; i++)
            {
                ssn.MessageTransfer("amq.direct", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED,
                                    new Header(new DeliveryProperties().SetRoutingKey("queue1"),
                                               new MessageProperties().SetMessageId(UUID.RandomUuid())),
                                    messageBody);
            }
            ssn.Sync();

            lock (myLock)
            {
                if (myListener.Count != 0)
                {
                    Monitor.Wait(myLock, 10000000);
                }
            }
            Assert.IsTrue(myListener.Count == 0);
            ssn.MessageAccept(myListener.UnAck);
            ssn.Sync();
            // the queue should be empty
            result = (QueueQueryResult)ssn.QueueQuery("queue1").Result;
            Assert.IsTrue(result.GetMessageCount() == 0);
            ssn.Close();
        }
Esempio n. 9
0
        private void process(int size, string queue)
        {
            CircularBuffer <IMessage> buffer   = new CircularBuffer <IMessage>(100);
            IMessageListener          listener = new SyncListener(buffer);
            string localQueue = "queue-" + UUID.RandomUuid();

            Session.QueueDeclare(localQueue, null, null, Option.AUTO_DELETE);
            Session.ExchangeBind(localQueue, "amq.direct", queue);
            Session.AttachMessageListener(listener, localQueue);
            Session.MessageSubscribe(localQueue);
            for (int i = 0; i < size; ++i)
            {
                buffer.Dequeue();
            }
        }
Esempio n. 10
0
        public override void Start()
        {
            byte[] data = new byte[Options.Size];
            // randomly populate data
            Random r = new Random(34);

            r.NextBytes(data);
            IMessage message = new Message();

            message.AppendData(data);

            message.DeliveryProperties.SetRoutingKey(_key);

            if (Options.Durable)
            {
                message.DeliveryProperties.SetDeliveryMode(MessageDeliveryMode.PERSISTENT);
            }

            if (Options.Tx > 0)
            {
                Session.TxSelect();
                Session.Sync();
            }

            CircularBuffer <IMessage> buffer = new CircularBuffer <IMessage>(100);
            // Create a listener and subscribe it to the queue named "pub_start"
            IMessageListener listener   = new SyncListener(buffer);
            string           localQueue = "localQueue-" + UUID.RandomUuid().ToString();

            Session.QueueDeclare(localQueue, null, null, Option.AUTO_DELETE);
            Session.ExchangeBind(localQueue, "amq.direct", "pub_start");
            Session.AttachMessageListener(listener, localQueue);
            Session.MessageSubscribe(localQueue);
            if (Options.Tx > 0)
            {
                Session.TxCommit();
                Session.Sync();
            }
            buffer.Dequeue();

            for (int j = 0; j < Options.Iterations; ++j)
            {
                DateTime start = DateTime.Now;
                for (long i = 0; i < Options.Count; ++i)
                {
                    Session.MessageTransfer(_exchange, message);

                    if (Options.SyncPub)
                    {
                        Session.Sync();
                    }
                    if (Options.Tx > 0 && (i + 1) % Options.Tx == 0)
                    {
                        Session.TxSelect();
                        Session.Sync();
                    }
                    if (Options.IntervalPub > 0)
                    {
                        Thread.Sleep((int)Options.IntervalSub * 1000);
                    }
                }
                Session.Sync();
                DateTime end = DateTime.Now;

                // Report to publisher.
                message.DeliveryProperties.SetRoutingKey("pub_done");
                message.ClearData();
                double time = end.Subtract(start).TotalMilliseconds;
                byte[] rate = BitConverter.GetBytes(Options.Count / time);
                message.AppendData(rate);
                Session.MessageTransfer("amq.direct", message);
                if (Options.Tx > 0)
                {
                    Session.TxSelect();
                    Session.Sync();
                }
            }
            Session.Close();
        }
Esempio n. 11
0
        public override void Start()
        {
            if (Options.Tx > 0)
            {
                Session.TxSelect();
                Session.Sync();
            }
            CircularBuffer <IMessage> buffer = new CircularBuffer <IMessage>(100);
            // Create a listener and subscribe it to the queue named "message_queue"
            IMessageListener listener = new SyncListener(buffer);

            string dest = "dest" + UUID.RandomUuid();

            Session.AttachMessageListener(listener, dest);
            Session.MessageSubscribe(_queue, dest,
                                     Options.Tx > 0 || Options.SubAck > 0
                                         ? MessageAcceptMode.EXPLICIT
                                         : MessageAcceptMode.NONE,
                                     MessageAcquireMode.PRE_ACQUIRED, null, 0, null);
            // issue credits
            Session.MessageSetFlowMode(dest, MessageFlowMode.WINDOW);
            Session.MessageFlow(dest, MessageCreditUnit.BYTE, ClientSession.MESSAGE_FLOW_MAX_BYTES);

            // Notify controller we are ready.
            IMessage message = new Message();

            message.DeliveryProperties.SetRoutingKey("sub_ready");

            message.AppendData(Encoding.UTF8.GetBytes("ready"));
            Session.MessageTransfer("amq.direct", message);

            if (Options.Tx > 0)
            {
                Session.TxCommit();
                Session.Sync();
            }


            for (int j = 0; j < Options.Iterations; ++j)
            {
                //need to allocate some more credit
                Session.MessageFlow(dest, MessageCreditUnit.MESSAGE, (long)Options.SubQuota);

                RangeSet range = new RangeSet();
                IMessage msg;
                DateTime start = DateTime.Now;
                for (long i = 0; i < Options.SubQuota; ++i)
                {
                    msg = buffer.Dequeue();
                    if (Options.Tx > 0 && ((i + 1) % Options.Tx == 0))
                    {
                        Session.TxCommit();
                        Session.Sync();
                    }
                    if (Options.IntervalSub > 0)
                    {
                        Thread.Sleep((int)Options.IntervalSub * 1000);
                    }
                    range.Add(msg.Id);
                }
                if (Options.Tx > 0 || Options.SubAck > 0)
                {
                    Session.MessageAccept(range);
                }
                range.Clear();
                if (Options.Tx > 0)
                {
                    Session.TxSelect();
                    Session.Sync();
                }
                DateTime end = DateTime.Now;

                // Report to publisher.
                message.DeliveryProperties.SetRoutingKey("sub_done");
                message.ClearData();
                message.AppendData(BitConverter.GetBytes(Options.SubQuota / end.Subtract(start).TotalMilliseconds));
                Session.MessageTransfer("amq.direct", message);
                if (Options.Tx > 0)
                {
                    Session.TxSelect();
                    Session.Sync();
                }
            }
            Session.Close();
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure(new FileInfo("..\\..\\log.xml"));
            // DOMConfigurator.Configure()

            string          host           = ConfigurationManager.AppSettings["Host"];
            int             port           = int.Parse(ConfigurationManager.AppSettings["Port"]);
            string          virtualhost    = ConfigurationManager.AppSettings["VirtualHost"];
            string          username       = ConfigurationManager.AppSettings["Username"];
            string          password       = ConfigurationManager.AppSettings["Password"];
            IConnectionInfo connectionInfo = new QpidConnectionInfo();

            connectionInfo.VirtualHost = virtualhost;
            //connectionInfo.host = host;
            //connectionInfo.port = port;
            connectionInfo.Username = username;
            connectionInfo.Password = password;

            //Client client = new Client();

            Console.WriteLine("Client created");
            //client.Connect(host, port, virtualhost, username, password);
            IConnection clientConnection = new AMQConnection(connectionInfo);

            Console.WriteLine("Connection established");

            IClientSession ssn = client.CreateSession(50000);

            Console.WriteLine("Session created");
            ssn.QueueDeclare("queue1", null, null);
            ssn.ExchangeBind("queue1", "amq.direct", "queue1", null);


            Object wl = new Object();

            ssn.AttachMessageListener(new MyListener(ssn, wl), "myDest");

            ssn.MessageSubscribe("queue1", "myDest", MessageAcceptMode.EXPLICIT, MessageAcquireMode.PRE_ACQUIRED, null,
                                 0, null);
            DateTime start = DateTime.Now;

            // issue credits
            ssn.MessageSetFlowMode("myDest", MessageFlowMode.WINDOW);
            ssn.MessageFlow("myDest", MessageCreditUnit.BYTE, ClientSession.MESSAGE_FLOW_MAX_BYTES);
            ssn.MessageFlow("myDest", MessageCreditUnit.MESSAGE, 10000);
            ssn.Sync();


            for (int i = 0; i < 10000; i++)
            {
                ssn.MessageTransfer("amq.direct", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED,
                                    new Header(new DeliveryProperties().SetRoutingKey("queue1"),
                                               new MessageProperties().SetMessageId(UUID.RandomUuid())),
                                    Encoding.UTF8.GetBytes("test: " + i));
            }

            lock (wl)
            {
                Monitor.Wait(wl);
            }
            DateTime now = DateTime.Now;

            Console.WriteLine("Start time " + start + " now: " + now);

            Console.WriteLine("Done time: " + (now - start));
            lock (wl)
            {
                Monitor.Wait(wl, 30000);
            }
            client.Close();
        }