Beispiel #1
0
        public AmqpProperties Clone()
        {
            // memberwise clone ok for string, byte[], and value types
            AmqpProperties clonedProps = (AmqpProperties)this.MemberwiseClone();

            // deeper copy for the dictionary
            if (this.propertyMap != null)
            {
                if (this.propertyMap.Count > 0)
                {
                    Dictionary <string, AmqpType> clonedDictionary = new Dictionary <string, AmqpType>(this.propertyMap.Count);
                    foreach (KeyValuePair <string, AmqpType> original in this.propertyMap)
                    {
                        clonedDictionary.Add(original.Key, original.Value.Clone());
                    }

                    clonedProps.propertyMap = clonedDictionary;
                }
                else
                {
                    clonedProps.propertyMap = null;
                }
            }
            return(clonedProps);
        }
Beispiel #2
0
 internal AmqpChannelProperties()
 {
     this.brokerHost = AmqpDefaults.BrokerHost;
     this.brokerPort = AmqpDefaults.BrokerPort;
     this.transferMode = AmqpDefaults.TransferMode;
     this.defaultMessageProperties = null;
     this.amqpSecurityMode = AmqpSecurityMode.None;
     this.amqpTransportSecurity = null;
     this.amqpCredential = null;
     this.maxBufferPoolSize = AmqpDefaults.MaxBufferPoolSize;
     this.maxReceivedMessageSize = AmqpDefaults.MaxReceivedMessageSize;
 }
Beispiel #3
0
        // adds/replaces from the other AmqpProperty object.
        // just inserts references, i.e. provides shallow copy semantics (see Clone for deep copy)
        public void MergeFrom(AmqpProperties other)
        {
            if (other.timeToLive.HasValue)
            {
                this.timeToLive = other.timeToLive;
            }

            if ((other.replyToRoutingKey != null) || (other.replyToExchange != null))
            {
                this.replyToExchange   = other.replyToExchange;
                this.replyToRoutingKey = other.replyToRoutingKey;
            }

            if (other.subject != null)
            {
                this.subject = other.subject;
            }

            if (other.durable)
            {
                this.durable = true;
            }

            if (other.contentType != null)
            {
                this.contentType = other.contentType;
            }

            if (other.correlationId != null)
            {
                this.correlationId = other.correlationId;
            }

            if (other.userId != null)
            {
                this.userId = other.userId;
            }

            if (other.propertyMap != null)
            {
                if (other.propertyMap.Count > 0)
                {
                    Dictionary <string, AmqpType> thisMap = this.PropertyMap;
                    foreach (KeyValuePair <string, AmqpType> kvp in other.propertyMap)
                    {
                        thisMap[kvp.Key] = kvp.Value;
                    }
                }
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            try
            {
                Options options = new Options(args);

                AmqpBinaryBinding binding = new AmqpBinaryBinding();
                binding.BrokerHost = options.Broker;
                binding.BrokerPort = options.Port;
                binding.TransferMode = TransferMode.Streamed;

                IChannelFactory<IOutputChannel> factory = binding.BuildChannelFactory<IOutputChannel>();

                factory.Open();
                try
                {
                    System.ServiceModel.EndpointAddress addr = options.Address;
                    IOutputChannel sender = factory.CreateChannel(addr);
                    sender.Open();

                    MyRawBodyWriter.Initialize(options.Content);
                    DateTime end = DateTime.Now.Add(options.Timeout);
                    System.ServiceModel.Channels.Message message;

                    for (int count = 0; ((count < options.Count) || (options.Count == 0)) &&
                        ((options.Timeout == TimeSpan.Zero) || (end.CompareTo(DateTime.Now) > 0)); count++)
                    {
                        message = Message.CreateMessage(MessageVersion.None, "", new MyRawBodyWriter());
                        AmqpProperties props = new AmqpProperties();
                        props.ContentType = "text/plain";

                        string id = Guid.NewGuid().ToString() + ":" + count;
                        props.PropertyMap.Add("spout-id", new AmqpString(id));

                        message.Properties["AmqpProperties"] = props;
                        sender.Send(message);
                    }
                }
                finally
                {
                    factory.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Spout: " + e);
            }
        }
Beispiel #5
0
        private static string MessageContentAsString(Message msg, AmqpProperties props)
        {
            // AmqpBinaryBinding provides message content as a single XML "Binary" element
            XmlDictionaryReader reader = msg.GetReaderAtBodyContents();
            while (!reader.HasValue)
            {
                reader.Read();
                if (reader.EOF)
                {
                    throw new InvalidDataException("empty reader for message");
                }
            }

            byte[] rawdata = reader.ReadContentAsBase64();

            string ct = props.ContentType;
            if (ct != null)
            {
                if (ct.Equals("amqp/map"))
                {
                    return "mapdata (coming soon)";
                }
            }

            return Encoding.UTF8.GetString(rawdata);
        }
Beispiel #6
0
        private static string MessagePropertiesAsString(AmqpProperties props)
        {
            StringBuilder sb = new StringBuilder();

            if (props.PropertyMap != null)
            {
                foreach (KeyValuePair<string, AmqpType> kvp in props.PropertyMap)
                {
                    string propval;
                    if (kvp.Value is AmqpString)
                    {
                        AmqpString amqps = (AmqpString)kvp.Value;
                        propval = amqps.Value;
                    }
                    else
                    {
                        propval = kvp.Value.ToString();
                    }

                    Append(sb, kvp.Key + ":" + propval);
                }
            }

            return sb.ToString();
        }
Beispiel #7
0
        // adds/replaces from the other AmqpProperty object.
        // just inserts references, i.e. provides shallow copy semantics (see Clone for deep copy)
        public void MergeFrom(AmqpProperties other)
        {
            if (other.timeToLive.HasValue)
            {
                this.timeToLive = other.timeToLive;
            }

            if ((other.replyToRoutingKey != null) || (other.replyToExchange != null))
            {
                this.replyToExchange = other.replyToExchange;
                this.replyToRoutingKey = other.replyToRoutingKey;
            }

            if (other.subject != null)
            {
                this.subject = other.subject;
            }

            if (other.durable)
            {
                this.durable = true;
            }

            if (other.contentType != null)
            {
                this.contentType = other.contentType;
            }

            if (other.correlationId != null)
            {
                this.correlationId = other.correlationId;
            }

            if (other.userId != null)
            {
                this.userId = other.userId;
            }

            if (other.propertyMap != null)
            {
                if (other.propertyMap.Count > 0)
                {
                    Dictionary<string, AmqpType> thisMap = this.PropertyMap;
                    foreach (KeyValuePair<string, AmqpType> kvp in other.propertyMap)
                    {
                        thisMap[kvp.Key] = kvp.Value;
                    }
                }
            }
        }
Beispiel #8
0
        public void Run()
        {
            IRawBodyUtility bodyUtil = new RawEncoderUtility();

            IInputChannel startQueue = null;
            IOutputChannel doneQueue = null;
            UInt64 batchSize = (UInt64)opts.pubTxSize;
            bool txPending = false;
            AmqpProperties amqpProperties = null;

            if (opts.durable)
            {
                amqpProperties = new AmqpProperties();
                amqpProperties.Durable = true;
            }

            try
            {
                publishQueue = QueueChannelFactory.CreateWriterChannel(this.destination, this.routingKey);
                doneQueue = QueueChannelFactory.CreateWriterChannel("", this.Fqn("pub_done"));
                startQueue = QueueChannelFactory.CreateReaderChannel(this.Fqn("pub_start"));

                // wait for our start signal
                Message msg;
                msg = startQueue.Receive(TimeSpan.MaxValue);
                Expect(bodyUtil.GetText(msg), "start");
                msg.Close();

                Stopwatch stopwatch = new Stopwatch();
                AsyncCallback sendCallback = new AsyncCallback(this.AsyncSendCB);

                byte[] data = new byte[this.msgSize];
                IAsyncResult sendResult = null;

                Console.WriteLine("sending {0}", this.msgCount);
                stopwatch.Start();

                if (batchSize > 0)
                {
                    Transaction.Current = new CommittableTransaction();
                }

                for (UInt64 i = 0; i < this.msgCount; i++)
                {
                    StampSequenceNo(data, i);
                    msg = bodyUtil.CreateMessage(data);
                    if (amqpProperties != null)
                    {
                        msg.Properties.Add("AmqpProperties", amqpProperties);
                    }

                    sendResult = publishQueue.BeginSend(msg, TimeSpan.MaxValue, sendCallback, msg);

                    if (batchSize > 0)
                    {
                        txPending = true;
                        if (((i + 1) % batchSize) == 0)
                        {
                            ((CommittableTransaction)Transaction.Current).Commit();
                            txPending = false;
                            Transaction.Current = new CommittableTransaction();
                        }
                    }
                }

                if (txPending)
                {
                    ((CommittableTransaction)Transaction.Current).Commit();
                }

                Transaction.Current = null;

                sendResult.AsyncWaitHandle.WaitOne();
                stopwatch.Stop();

                double mps = (msgCount / stopwatch.Elapsed.TotalSeconds);

                msg = bodyUtil.CreateMessage(String.Format("{0:0.##}", mps));
                doneQueue.Send(msg, TimeSpan.MaxValue);
                msg.Close();
            }
            finally
            {
                Close((IChannel)doneQueue);
                Close((IChannel)publishQueue);
                Close(startQueue);
            }
        }