Exemplo n.º 1
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);
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called whenever Excel requests a new RTD topic from the RealTimeData server.
        /// </summary>
        /// <param name="TopicID"></param>
        /// <param name="Strings"></param>
        /// <param name="GetNewValues"></param>
        /// <returns></returns>
        public object ConnectData(int TopicID, ref Array Strings, ref bool GetNewValues)
        {
            try
            {
                string queuename       = "defaultExcelAddInQueue";
                string destinationName = "ExcelAddIn-" + queuename;
                if (Strings.Length > 0)
                {
                    queuename = (string)Strings.GetValue(0);
                }
                // Error message if the queue does not exist
                QueueQueryResult result = (QueueQueryResult)_session.QueueQuery(queuename).Result;
                if (result.GetQueue() == null)
                {
                    System.Windows.Forms.MessageBox.Show("Error: \n queue " + queuename + " does not exist");
                    return("error");
                }

                QpidListener listener;
                _topicMessages.Add(TopicID, null);
                _topicQueueName.Add(TopicID, queuename);
                if (_queueListener.ContainsKey(queuename))
                {
                    listener = _queueListener[queuename];
                    listener.addTopic(TopicID);
                }
                else
                {
                    listener = new QpidListener(this);
                    listener.addTopic(TopicID);
                    _queueListener.Add(queuename, listener);
                    _session.AttachMessageListener(listener, destinationName);
                    _session.MessageSubscribe(queuename, destinationName, MessageAcceptMode.EXPLICIT,
                                              MessageAcquireMode.PRE_ACQUIRED, null, 0, null);
                    // issue credits
                    _session.MessageSetFlowMode(destinationName, MessageFlowMode.WINDOW);
                    _session.MessageFlow(destinationName, MessageCreditUnit.BYTE, ClientSession.MESSAGE_FLOW_MAX_BYTES);
                    _session.MessageFlow(destinationName, MessageCreditUnit.MESSAGE, 1000);
                    _session.Sync();
                }
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Error: \n" + e.StackTrace);
                return("error");
            }
            return("waiting");
        }