Beispiel #1
0
        public void Add(TimeoutData timeout)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();

                using (var command = BuildAddCommand(connection, timeout))
                {
                    command.ExecuteNonQuery();
                }
            }
        }
        public void Add(Guid correlationId, TimeSpan timeToLive, object message, IDictionary<string, string> headers)
        {
            Mandate.ParameterNotNull(message, "messages");

            var serializedMessages = messageSerializer.Serialize(message);

            var timeoutData = new TimeoutData
            {
                MessageId = SequentialGuid.New(),
                CorrelationId = correlationId,
                Body = serializedMessages,
                DestinationAddress = Address.Local.ToString(),
                Expires = DateTime.MaxValue,
                Headers = headers
            };

            Add(timeoutData);
        }
Beispiel #3
0
        private SqlCommand BuildAddCommand(SqlConnection connection, TimeoutData timoutData)
        {
            var command = connection.CreateCommand();
            command.CommandText = String.Format(SqlCommands.AddTimeout, Address.Local);
            command.CommandType = CommandType.Text;

            command.Parameters.AddWithValue("@Id", timoutData.MessageId);
            command.Parameters.AddWithValue("@Destination", timoutData.DestinationAddress);
            command.Parameters.AddWithValue("@Headers", objectSerializer.SerializeObject(timoutData.Headers));
            command.Parameters.AddWithValue("@Expires", timoutData.Expires);
            command.Parameters.AddWithValue("@Body", timoutData.Body);

            if (timoutData.CorrelationId != Guid.Empty)
            {
                command.Parameters.AddWithValue("@CorrelationId", timoutData.CorrelationId);
            }
            else
            {
                command.Parameters.AddWithValue("@CorrelationId", DBNull.Value);
            }

            return command;
        }
Beispiel #4
0
        public bool TryFetchNextTimeout(out TimeoutData timeoutData)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();

                using (var command = new SqlCommand(String.Format(SqlCommands.TryRemoveTimeout, Address.Local), connection))
                {
                    using (var dataReader = command.ExecuteReader())
                    {
                        timeoutData = FoundTimeoutData(dataReader);
                        return timeoutData != null;
                    }
                }
            }
        }