Exemple #1
0
        public IEnumerable <Message> GetAllMessages(string queue)
        {
            var rawList = new List <RawMessage>();

            using (var tx = BeginTransaction())
            {
                using (var command = tx.Connection.CreateCommand())
                {
                    command.CommandTimeout = 240;
                    command.CommandText    = "Queue.RecieveMessages";
                    command.CommandType    = CommandType.StoredProcedure;
                    command.Transaction    = tx.Transaction;
                    command.Parameters.AddWithValue("@Endpoint", _endpoint.ToString());
                    command.Parameters.AddWithValue("@Queue", _queueName);
                    command.Parameters.AddWithValue("@SubQueue", queue);

                    var reader               = command.ExecuteReader();
                    var messageIdIndex       = reader.GetOrdinal("MessageId");
                    var queueIdIndex         = reader.GetOrdinal("QueueId");
                    var createdAtIndex       = reader.GetOrdinal("CreatedAt");
                    var processingUntilIndex = reader.GetOrdinal("ProcessingUntil");
                    var processedIndex       = reader.GetOrdinal("Processed");
                    var headersIndex         = reader.GetOrdinal("Headers");
                    var payloadIndex         = reader.GetOrdinal("Payload");
                    while (reader.Read())
                    {
                        var raw = new RawMessage
                        {
                            CreatedAt       = reader.GetDateTime(createdAtIndex),
                            Headers         = reader.GetString(headersIndex),
                            MessageId       = reader.GetInt64(messageIdIndex),
                            Processed       = reader.GetBoolean(processedIndex),
                            ProcessingUntil = reader.GetDateTime(processingUntilIndex),
                            QueueId         = reader.GetInt32(queueIdIndex),
                            SubQueueName    = queue
                        };
                        var binValue = reader.GetSqlBinary(payloadIndex);
                        if (!binValue.IsNull)
                        {
                            raw.Payload = binValue.Value;
                        }
                        rawList.Add(raw);
                    }
                    reader.Close();
                }
                tx.Transaction.Commit();
            }
            return(rawList.Select(raw => raw.ToMessage()));
        }
Exemple #2
0
        public Message Receive(int queueId, TimeSpan timeOut)
        {
            RawMessage raw = null;

            using (var command = SqlTransactionContext.Current.Connection.CreateCommand())
            {
                command.CommandTimeout = timeOut.Seconds;
                command.CommandText    = "Queue.RecieveMessage";
                command.CommandType    = CommandType.StoredProcedure;
                command.Transaction    = SqlTransactionContext.Current.Transaction;
                command.Parameters.AddWithValue("@QueueId", queueId);

                var reader               = command.ExecuteReader();
                var messageIdIndex       = reader.GetOrdinal("MessageId");
                var createdAtIndex       = reader.GetOrdinal("CreatedAt");
                var processingUntilIndex = reader.GetOrdinal("ProcessingUntil");
                var processedCountIndex  = reader.GetOrdinal("ProcessedCount");
                var processedIndex       = reader.GetOrdinal("Processed");
                var headersIndex         = reader.GetOrdinal("Headers");
                var payloadIndex         = reader.GetOrdinal("Payload");
                while (reader.Read())
                {
                    raw = new RawMessage
                    {
                        CreatedAt       = reader.GetDateTime(createdAtIndex),
                        Headers         = reader.GetString(headersIndex),
                        MessageId       = reader.GetInt64(messageIdIndex),
                        Processed       = reader.GetBoolean(processedIndex),
                        ProcessingUntil = reader.GetDateTime(processingUntilIndex),
                        ProcessedCount  = reader.GetInt32(processedCountIndex),
                        QueueId         = queueId,
                        SubQueueName    = null
                    };

                    if (!reader.IsDBNull(payloadIndex))
                    {
                        raw.Payload = reader.GetSqlBinary(payloadIndex).Value;
                    }
                }
                reader.Close();
            }

            if (raw == null)
            {
                throw new TimeoutException();
            }
            return(raw.ToMessage());
        }
        public IEnumerable<Message> GetAllMessages(string queue)
        {
            var rawList = new List<RawMessage>();
            using (var tx = BeginTransaction())
            {
                using (var command = tx.Connection.CreateCommand())
				{
					command.CommandTimeout = 240;
                    command.CommandText = "Queue.RecieveMessages";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Transaction = tx.Transaction;
                    command.Parameters.AddWithValue("@Endpoint", _endpoint.ToString());
                    command.Parameters.AddWithValue("@Queue", _queueName);
                    command.Parameters.AddWithValue("@SubQueue", queue);

                    var reader = command.ExecuteReader();
                    var messageIdIndex = reader.GetOrdinal("MessageId");
                    var queueIdIndex = reader.GetOrdinal("QueueId");
                    var createdAtIndex = reader.GetOrdinal("CreatedAt");
                    var processingUntilIndex = reader.GetOrdinal("ProcessingUntil");
                    var processedIndex = reader.GetOrdinal("Processed");
                    var headersIndex = reader.GetOrdinal("Headers");
                    var payloadIndex = reader.GetOrdinal("Payload");
                    while (reader.Read())
                    {
                        var raw = new RawMessage
                        {
                            CreatedAt = reader.GetDateTime(createdAtIndex),
                            Headers = reader.GetString(headersIndex),
                            MessageId = reader.GetInt64(messageIdIndex),
                            Processed = reader.GetBoolean(processedIndex),
                            ProcessingUntil = reader.GetDateTime(processingUntilIndex),
                            QueueId = reader.GetInt32(queueIdIndex),
                            SubQueueName = queue
                        };
                        var binValue = reader.GetSqlBinary(payloadIndex);
                        if (!binValue.IsNull)
                        {
                            raw.Payload = binValue.Value;
                        }
                        rawList.Add(raw);
                    }
                    reader.Close();
                }
                tx.Transaction.Commit();
            }
            return rawList.Select(raw => raw.ToMessage());
        }
        public Message Receive(int queueId, TimeSpan timeOut)
        {
            RawMessage raw = null;

            using (var command = SqlTransactionContext.Current.Connection.CreateCommand())
            {
                command.CommandTimeout = timeOut.Seconds;
                command.CommandText = "Queue.RecieveMessage";
                command.CommandType = CommandType.StoredProcedure;
                command.Transaction = SqlTransactionContext.Current.Transaction;
                command.Parameters.AddWithValue("@QueueId", queueId);

                var reader = command.ExecuteReader();
                var messageIdIndex = reader.GetOrdinal("MessageId");
                var createdAtIndex = reader.GetOrdinal("CreatedAt");
                var processingUntilIndex = reader.GetOrdinal("ProcessingUntil");
                var processedCountIndex = reader.GetOrdinal("ProcessedCount");
                var processedIndex = reader.GetOrdinal("Processed");
                var headersIndex = reader.GetOrdinal("Headers");
                var payloadIndex = reader.GetOrdinal("Payload");
                while (reader.Read())
                {
                    raw = new RawMessage
                              {
                                  CreatedAt = reader.GetDateTime(createdAtIndex),
                                  Headers = reader.GetString(headersIndex),
                                  MessageId = reader.GetInt64(messageIdIndex),
                                  Processed = reader.GetBoolean(processedIndex),
                                  ProcessingUntil = reader.GetDateTime(processingUntilIndex),
                                  ProcessedCount = reader.GetInt32(processedCountIndex),
                                  QueueId = queueId,
                                  SubQueueName = null
                              };
                    
                    if (!reader.IsDBNull(payloadIndex))
                        raw.Payload = reader.GetSqlBinary(payloadIndex).Value;
                }
                reader.Close();
            }
            
            if (raw==null) throw new TimeoutException();
            return raw.ToMessage();
        }
        public Message PeekById(int messageId)
        {
            RawMessage raw = null;

            using (var command = SqlTransactionContext.Current.Connection.CreateCommand())
            {
                command.CommandText = "Queue.PeekMessageById";
                command.CommandType = CommandType.StoredProcedure;
                command.Transaction = SqlTransactionContext.Current.Transaction;
                command.Parameters.AddWithValue("@MessageId", messageId);

                var reader = command.ExecuteReader();
                var messageIdIndex = reader.GetOrdinal("MessageId");
                var queueIdIndex = reader.GetOrdinal("QueueId");
                var createdAtIndex = reader.GetOrdinal("CreatedAt");
                var processingUntilIndex = reader.GetOrdinal("ProcessingUntil");
                var processedIndex = reader.GetOrdinal("Processed");
                var headersIndex = reader.GetOrdinal("Headers");
                var payloadIndex = reader.GetOrdinal("Payload");
                var subQueueNameIndex = reader.GetOrdinal("SubqueueName");
                while (reader.Read())
                {
                    raw = new RawMessage
                              {
                                  CreatedAt = reader.GetDateTime(createdAtIndex),
                                  Headers = reader.GetString(headersIndex),
                                  MessageId = reader.GetInt32(messageIdIndex),
                                  Processed = reader.GetBoolean(processedIndex),
                                  ProcessingUntil = reader.GetDateTime(processingUntilIndex),
                                  QueueId = reader.GetInt32(queueIdIndex)
                              };

                    if (!reader.IsDBNull(subQueueNameIndex))
                        raw.SubQueueName = reader.GetString(subQueueNameIndex);
                    if (!reader.IsDBNull(payloadIndex))
                    raw.Payload = reader.GetSqlBinary(payloadIndex).Value;
                }
                reader.Close();
            }
            return raw == null ? null : raw.ToMessage();
        }