Beispiel #1
0
        public static void ProcessSingleDelivery(BasicDeliverEventArgs e)
        {
            Console.WriteLine("Delivery =========================================");
            DebugUtil.DumpProperties(e, Console.Out, 0);
            Console.WriteLine("----------------------------------------");

            if (e.BasicProperties.ContentType == MapMessageReader.MimeType)
            {
                IMapMessageReader r = new MapMessageReader(e.BasicProperties, e.Body);
                DebugUtil.DumpProperties(r.Body, Console.Out, 0);
            }
            else if (e.BasicProperties.ContentType == StreamMessageReader.MimeType)
            {
                IStreamMessageReader r = new StreamMessageReader(e.BasicProperties, e.Body);
                while (true)
                {
                    try {
                        object v = r.ReadObject();
                        Console.WriteLine("(" + v.GetType() + ") " + v);
                    } catch (EndOfStreamException) {
                        break;
                    }
                }
            }
            else
            {
                // No special content-type. Already covered by the DumpProperties above.
            }

            Console.WriteLine("==================================================");
        }
Beispiel #2
0
        protected string GetType(byte[] byteData, IBasicProperties props)
        {
            IMapMessageReader r   = new MapMessageReader(props, byteData);
            var messageProperties = new Dictionary <string, string>();

            foreach (string key in r.Body.Keys)
            {
                messageProperties.Add(key, r.Body[key].ToString());
            }
            return(messageProperties["Type"]);
        }
        /// <summary>
        /// Получение из свойств тела сообщения и свойств сообщения сообщения в формате шины.
        /// </summary>
        /// <param name="bodyProperties">Свойства тела сообщения.</param>
        /// <param name="properties">Свойства сообщения (тэги).</param>
        /// <returns>Сообщение в формате шины.</returns>
        public MessageWithNotTypedPk ConvertFromMqFormat(byte[] messagePayload, IDictionary <string, object> properties)
        {
            var result = new MessageWithNotTypedPk();

            BasicProperties rmqProperties = new RabbitMQ.Client.Framing.BasicProperties();

            rmqProperties.Headers = properties;
            var mapMessageReader = new MapMessageReader(rmqProperties, messagePayload);

            var bodyProperties = mapMessageReader.Body;

            if (bodyProperties.ContainsKey(this._bodyPropertyName))
            {
                result.Body = (string)mapMessageReader.Body[this._bodyPropertyName];
            }

            if (bodyProperties.ContainsKey(this._attachmentPropertyName))
            {
                result.BinaryAttachment = (byte[])mapMessageReader.Body[this._attachmentPropertyName];
            }

            if (bodyProperties.ContainsKey(this._senderIdPropepertyName))
            {
                result.Sender = (string)mapMessageReader.Body[this._senderIdPropepertyName];
            }

            var headers = mapMessageReader.Properties.Headers;

            if (headers != null)
            {
                var messageTags = new Dictionary <string, string>();
                foreach (var property in headers)
                {
                    if (property.Key.StartsWith(this._tagPropertiesPrefix))
                    {
                        var tagKey = property.Key.Substring(this._tagPropertiesPrefix.Length);
                        var value  = Encoding.UTF8.GetString((byte[])property.Value);
                        messageTags.Add(tagKey, value);
                    }
                }

                if (headers.ContainsKey(this.TimestampPropertyName))
                {
                    var unixtimestamp = (long)headers[this.TimestampPropertyName];
                    result.ReceivingTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc).AddMilliseconds(unixtimestamp);
                }

                result.Tags = messageTags.Any() ? messageTags.Select(x => $"{x.Key}:{x.Value}").Aggregate((x, y) => $"{x}, {y}") : "";
            }

            return(result);
        }
Beispiel #4
0
        public override void Deserialize(byte[] byteData, IBasicProperties props)
        {
            base.Deserialize(byteData, props);

            IMapMessageReader r   = new MapMessageReader(props, byteData);
            var messageProperties = new Dictionary <string, string>();

            foreach (string key in r.Body.Keys)
            {
                messageProperties.Add(key, r.Body[key].ToString());
            }

            Result = messageProperties["Result"];
        }
Beispiel #5
0
        public virtual void Deserialize(byte[] byteData, IBasicProperties props)
        {
            IMapMessageReader r   = new MapMessageReader(props, byteData);
            var messageProperties = new Dictionary <string, string>();

            foreach (string key in r.Body.Keys)
            {
                messageProperties.Add(key, r.Body[key].ToString());
            }

            var namespaceType = messageProperties["Type"];

            PipelineObjectNamespaceName = namespaceType;
            PipelineObject = Type.GetType(namespaceType);
        }