예제 #1
0
        public IMessage ReadMessage(QueueReference destination, BasicDeliverEventArgs result)
        {
            /*
             * if (destination == null)
             *      throw new ArgumentException ("destination must not be null");
             * if (result == null)
             *      throw new ArgumentException ("result must not be null");
             */
            MessageBase msg = new MessageBase();
            Stream      s   = new MemoryStream();

            s.Write(result.Body, 0, result.Body.Length);
            DateTime    arrivedTime   = DateTime.Now;
            IDictionary headers       = result.BasicProperties.Headers;
            long        senderVersion = (long)headers[SENDER_VERSION_KEY];
            string      sourceMachine = GetString(headers, SOURCE_MACHINE_KEY);
            DateTime    sentTime      = AmqpTimestampToDateTime(result.BasicProperties.Timestamp);
            string      transactionId = GetString(headers, TRANSACTION_ID_KEY);

            msg.SetDeliveryInfo(Acknowledgment.None,
                                arrivedTime,
                                new RabbitMQMessageQueue(provider,
                                                         destination,
                                                         true),
                                result.BasicProperties.MessageId,
                                MessageType.Normal,
                                new byte[0],
                                senderVersion,
                                sentTime,
                                sourceMachine,
                                transactionId);
            msg.CorrelationId   = result.BasicProperties.CorrelationId;
            msg.BodyStream      = s;
            msg.BodyType        = (int)result.BasicProperties.Headers[BODY_TYPE_KEY];
            msg.AcknowledgeType = (AcknowledgeTypes)
                                  Enum.ToObject(typeof(AcknowledgeTypes),
                                                headers[ACKNOWLEDGE_TYPE_KEY]);
            string adminQueuePath = GetString(headers, ADMINISTRATION_QUEUE_KEY);

            if (adminQueuePath != null)
            {
                QueueReference qRef = QueueReference.Parse(adminQueuePath);
                msg.AdministrationQueue = new RabbitMQMessageQueue(provider,
                                                                   qRef,
                                                                   true);
            }
            msg.AppSpecific = (int)headers[APP_SPECIFIC_KEY];
            msg.AuthenticationProviderName = GetString(headers, AUTHENTICATION_PROVIDER_NAME_KEY);
            msg.AuthenticationProviderType = (CryptographicProviderType)Enum.ToObject(typeof(CryptographicProviderType), headers[AUTHENTICATION_PROVIDER_TYPE_KEY]);
            string connectorType = GetString(headers, CONNECTOR_TYPE_KEY);

            msg.ConnectorType           = new Guid(connectorType);
            msg.DestinationSymmetricKey = (byte[])headers[DESTINATION_SYMMETRIC_KEY_KEY];
            msg.DigitalSignature        = (byte[])headers[DIGITAL_SIGNATURE_KEY];
            msg.EncryptionAlgorithm     = (EncryptionAlgorithm)Enum.ToObject(typeof(EncryptionAlgorithm), headers[ENCRYPTION_ALGORITHM_KEY]);
            msg.Extension     = (byte[])headers[EXTENSION_KEY];
            msg.HashAlgorithm = (HashAlgorithm)Enum.ToObject(typeof(HashAlgorithm), headers[HASH_ALGORITHM_KEY]);
            msg.Label         = GetString(headers, LABEL_KEY);
            msg.Priority      = (MessagePriority)Enum.ToObject(typeof(MessagePriority), result.BasicProperties.Priority);
            msg.Recoverable   = result.BasicProperties.DeliveryMode == PERSISTENT_DELIVERY_MODE;
            if (result.BasicProperties.ReplyTo != null)
            {
                msg.ResponseQueue = new RabbitMQMessageQueue(provider, QueueReference.Parse(result.BasicProperties.ReplyTo), true);
            }
            msg.SenderCertificate  = (byte[])headers[SENDER_CERTIFICATE_KEY];
            msg.TimeToBeReceived   = new TimeSpan((long)headers[TIME_TO_BE_RECEIVED_KEY]);
            msg.TimeToReachQueue   = new TimeSpan((long)headers[TIME_TO_REACH_QUEUE_KEY]);
            msg.UseAuthentication  = (bool)headers[USE_AUTHENTICATION_KEY];
            msg.UseDeadLetterQueue = (bool)headers[USE_DEAD_LETTER_QUEUE_KEY];
            msg.UseEncryption      = (bool)headers[USE_ENCRYPTION_KEY];

            return(msg);
        }