Beispiel #1
0
        public IMessageProducer CreateProducer(IDestination destination)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }
            MessageProducer producer = null;

            try
            {
                Queue queue = new Queue(destination.ToString());
                producer = DoCreateMessageProducer(queue);

                this.AddProducer(producer);
            }
            catch (Exception)
            {
                if (producer != null)
                {
                    this.RemoveProducer(producer.ProducerId);
                    producer.Close();
                }

                throw;
            }

            return(producer);
        }
Beispiel #2
0
        private void PopulateAddressCombo()
        {
            store.Clear();

            TreeIter iter;

            if (networksComboBox.GetActiveIter(out iter))
            {
                Network selectedNetwork = networksListStore.GetValue(iter, 0) as Network;

                /*
                 * if (Core.ZeroconfManager != null) {
                 *      foreach (NearbyNode node in Core.NearbyNodes) {
                 *              if (node.NetworkId == selectedNetwork.NetworkID) {
                 *                      if (node.Port != TcpTransport.DefaultPort) {
                 *                              store.AppendValues(node, node.Address.ToString() + ":" + node.Port.ToString());
                 *                      } else {
                 *                              store.AppendValues(node, node.Address.ToString());
                 *                      }
                 *              }
                 *      }
                 * }
                 */

                foreach (TrustedNodeInfo node in selectedNetwork.TrustedNodes.Values)
                {
                    if (node.AllowConnect)
                    {
                        if (!IsNearby(node))
                        {
                            IDestination destination = node.GetFirstConnectableDestination(Runtime.Core);
                            if (destination != null)
                            {
                                store.AppendValues(node, destination.ToString());
                            }
                        }
                    }
                }

                if (store.IterNChildren() == 0)
                {
                    store.AppendValues(new object(), string.Empty);
                }

                ipCombo.Sensitive = true;
            }
            else
            {
                ipCombo.Sensitive  = false;
                ipCombo.Entry.Text = string.Empty;
            }
        }
Beispiel #3
0
        private int DrainDestination(IMessageConsumer drain, IDestination destination, int msgsToDrain = -1, int timeout = TIMEOUT)
        {
            int msgsDrained = 0;

            try
            {
                if (msgsToDrain > 0)
                {
                    while (msgsToDrain > msgsDrained)
                    {
                        IMessage msg = drain.Receive(TimeSpan.FromMilliseconds(timeout));
                        if (msg == null)
                        {
                            break;
                        }
                        msgsDrained++;
                    }
                }
                else
                {
                    IMessage msg = null;
                    while ((msg = drain.Receive(TimeSpan.FromMilliseconds(timeout))) != null)
                    {
                        msgsDrained++;
                    }
                }
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("Failed to drain Destination {0}", destination.ToString());
                if (msgsToDrain != -1)
                {
                    sb.AppendFormat(", Drained {0} of {1} messages", msgsDrained, msgsToDrain);
                }
                else
                {
                    sb.AppendFormat(", Drained {0} messages", msgsDrained);
                }
                if (timeout > 0)
                {
                    sb.AppendFormat(" in {0}ms", timeout);
                }

                throw new Exception(sb.ToString(), ex);
            }
            return(msgsDrained);
        }
Beispiel #4
0
        public BalanceSelector(IDestination destination)
        {
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }
            if (destination is BitcoinAddress || destination is BitcoinColoredAddress)
            {
                _Str = destination.ToString();
            }

            if (_Str == null)
            {
                _Str = "0x" + destination.ScriptPubKey.ToHex();
            }
        }
        /// <summary>
        /// The send object.
        /// </summary>
        /// <param name="session">
        /// The session.
        /// </param>
        /// <param name="t">
        /// The t.
        /// </param>
        /// <typeparam name="T">
        /// </typeparam>
        private static void SendObject <T>(ISession session, T t, string queueName)
        {
            //4.消息的目的地:destination
            IDestination dest = session.GetQueue(queueName);

            log.DebugFormat("ActiveMQ创建: {0}", dest.ToString());

            //5.创建用于发送消息的对象(设置其持久模式)
            using (IMessageProducer producer = session.CreateProducer(dest))
            {
                log.DebugFormat("ActiveMQ创建: {0}", producer.ToString());
                var objectMessage = producer.CreateObjectMessage(t);

                producer.Send(objectMessage);
                log.DebugFormat("ActiveMQ已发送: {0}", objectMessage.ToString());
            }
        }
Beispiel #6
0
        private void ShowAutoConnectIP(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
        {
            CellRendererText textCell = (CellRendererText)cell;

            if (((TreeStore)model).IterDepth(iter) > 0)
            {
                TrustedNodeInfo node        = (TrustedNodeInfo)model.GetValue(iter, 0);
                IDestination    destination = node.FirstConnectableDestination;
                if (destination == null)
                {
                    textCell.Text = "<unknown>";
                }
                else
                {
                    textCell.Text = destination.ToString();
                }
            }
            else
            {
                textCell.Text = String.Empty;
            }
        }
Beispiel #7
0
        /// <summary>
        /// The send object.
        /// </summary>
        /// <param name="session">
        /// The session.
        /// </param>
        /// <param name="t">
        /// The t.
        /// </param>
        /// <typeparam name="T">
        /// </typeparam>
        private static void SendObject <T>(ISession session, T t, string queueName, string selector)
        {
            //4.消息的目的地:destination
            IDestination dest = session.GetQueue(queueName);

            log.DebugFormat("ActiveMQ创建: {0}", dest.ToString());

            //5.创建用于发送消息的对象(设置其持久模式)
            using (IMessageProducer producer = session.CreateProducer(dest))
            {
                log.DebugFormat("ActiveMQ创建: {0}", producer.ToString());
                var objectMessage = producer.CreateObjectMessage(t);
                if (!string.IsNullOrEmpty(selector))
                {
                    var arr = selector.Split('=');
                    if (!arr.IsNullOrEmpty() && arr.Length == 2)
                    {
                        objectMessage.Properties.SetString(arr[0], arr[1].Replace("'", "").Replace("'", ""));
                    }
                }
                producer.Send(objectMessage);
                log.DebugFormat("ActiveMQ已发送: {0}", objectMessage.ToString());
            }
        }
Beispiel #8
0
        public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            MessageConsumer consumer = null;

            try
            {
                Queue queue = new Queue(destination.ToString());
                consumer = DoCreateMessageConsumer(GetNextConsumerId(), queue, acknowledgementMode);

                consumer.ConsumerTransformer = this.ConsumerTransformer;

                this.AddConsumer(consumer);

                if (this.Connection.IsStarted)
                {
                    consumer.Start();
                }
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    this.RemoveConsumer(consumer);
                    consumer.Close();
                }

                throw;
            }

            return(consumer);
        }
Beispiel #9
0
 /// <summary>
 /// Delete a destination (Queue, Topic, Temp Queue, Temp Topic).
 /// </summary>
 public void DeleteDestination(IDestination destination)
 {
     MessageQueue.Delete(destination.ToString());
 }
Beispiel #10
0
        public void TestCreateTemporaryDestination()
        {
            const int NUM_MSGS = 10;

            try
            {
                using (IConnection connection = GetConnection("default"))
                    using (ISession session = GetSession("s1"))
                    {
                        IStreamMessage msg = session.CreateStreamMessage();

                        IDestination temp = session.CreateTemporaryQueue();

                        IMessageProducer producer = session.CreateProducer(temp);

                        for (int i = 0; i < NUM_MSGS; i++)
                        {
                            msg.WriteObject("barfoo");
                            msg.WriteObject(i);

                            msg.Properties.SetInt("count", i);

                            producer.Send(msg);

                            msg.ClearBody();
                        }

                        // Queues do not require an active consumer to receive messages.
                        // Create consumer on queue after messages sent and receive messages.
                        IMessageConsumer drain = session.CreateConsumer(temp);

                        connection.Start();

                        int msgsReceived = DrainDestination(drain, temp, NUM_MSGS);

                        Assert.AreEqual(NUM_MSGS, msgsReceived, "Received {0} of {1} on temporary destination {2}.", msgsReceived, NUM_MSGS, temp.ToString());

                        temp = session.CreateTemporaryTopic();

                        // Topics require an active consumer to receive messages.
                        drain = session.CreateConsumer(temp);

                        producer = session.CreateProducer(temp);

                        for (int i = 0; i < NUM_MSGS; i++)
                        {
                            msg.WriteObject("foobar");
                            msg.WriteObject(i);

                            msg.Properties.SetInt("count", i);

                            producer.Send(msg);

                            msg.ClearBody();
                        }

                        msgsReceived = DrainDestination(drain, temp, NUM_MSGS);

                        Assert.AreEqual(NUM_MSGS, msgsReceived, "Received {0} of {1} on temporary destination {2}.", msgsReceived, NUM_MSGS, temp.ToString());
                    }
            }
            catch (Exception ex)
            {
                this.PrintTestFailureAndAssert(GetTestMethodName(), "Unexpected exception.", ex);
            }
        }
        public override bool Equals(object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return(false);
            }

            // If parameter cannot be cast to BaseMessage return false.
            BaseMessage p = obj as BaseMessage;

            if ((System.Object)p == null)
            {
                return(false);
            }

            if (propertiesMap == null ^ p.propertiesMap == null)
            {
                return(false);
            }
            if (propertiesMap != null)
            {
                if (!propertiesMap.ToString().Equals(p.propertiesMap.ToString()))
                {
                    return(false);
                }
            }

            if (destination == null ^ p.destination == null)
            {
                return(false);
            }
            if (destination != null)
            {
                if (!destination.ToString().Equals(p.destination.ToString()))
                {
                    return(false);
                }
            }

            if (correlationId == null ^ p.correlationId == null)
            {
                return(false);
            }
            if (correlationId != null)
            {
                if (!correlationId.Equals(p.correlationId))
                {
                    return(false);
                }
            }

            if (timeToLive == null ^ p.timeToLive == null)
            {
                return(false);
            }
            if (timeToLive != null)
            {
                if (!timeToLive.ToString().Equals(p.timeToLive.ToString()))
                {
                    return(false);
                }
            }

            if (messageId == null ^ p.messageId == null)
            {
                return(false);
            }
            if (messageId != null)
            {
                if (!messageId.Equals(p.messageId))
                {
                    return(false);
                }
            }

            if (deliveryMode != p.deliveryMode)
            {
                return(false);
            }

            if (priority != p.priority)
            {
                return(false);
            }

            if (replyTo == null ^ p.replyTo == null)
            {
                return(false);
            }
            if (replyTo != null)
            {
                if (!replyTo.ToString().Equals(p.replyTo.ToString()))
                {
                    return(false);
                }
            }

            if (content == null ^ p.content == null)
            {
                return(false);
            }
            if (content != null)
            {
                if (!content.ToString().Equals(p.content.ToString()))
                {
                    return(false);
                }
            }

            if (type == null ^ p.type == null)
            {
                return(false);
            }
            if (type != null)
            {
                if (!type.Equals(p.type))
                {
                    return(false);
                }
            }

            if (timestamp == null ^ p.timestamp == null)
            {
                return(false);
            }
            if (timestamp != null)
            {
                if (!timestamp.ToString().Equals(p.timestamp.ToString()))
                {
                    return(false);
                }
            }

            if (readOnlyMsgBody != p.readOnlyMsgBody)
            {
                return(false);
            }

            return(true);
        }
Beispiel #12
0
 public ConsumerTracker(ISession session, IDestination testDestination)
 {
     this.consumer = session.CreateConsumer(testDestination);
     Assert.IsNotNull(this.consumer, "Error creating consumer on {0}", testDestination.ToString());
 }
Beispiel #13
0
        public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            MessageConsumer consumer = null;

            try
            {
                Queue queue = new Queue(destination.ToString());
                consumer = DoCreateMessageConsumer(GetNextConsumerId(), queue, acknowledgementMode);

                consumer.ConsumerTransformer = this.ConsumerTransformer;

                this.AddConsumer(consumer);

                if (this.Connection.IsStarted)
                {
                    consumer.Start();
                }
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    this.RemoveConsumer(consumer);
                    consumer.Close();
                }

                throw;
            }

            return consumer;
        }
Beispiel #14
0
        public IMessageProducer CreateProducer(IDestination destination)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }
            MessageProducer producer = null;
            try
            {
                Queue queue = new Queue(destination.ToString());
                producer = DoCreateMessageProducer(queue);

                this.AddProducer(producer);
            }
            catch (Exception)
            {
                if (producer != null)
                {
                    this.RemoveProducer(producer.ProducerId);
                    producer.Close();
                }

                throw;
            }

            return producer;
        }