public void EnqueueDirectlyTo(string subQueue, MessagePayload messagePayload) { using (var command = SqlTransactionContext.Current.Connection.CreateCommand()) { command.CommandText = "Queue.EnqueueMessage"; command.CommandType = CommandType.StoredProcedure; command.Transaction = SqlTransactionContext.Current.Transaction; command.Parameters.AddWithValue("@Endpoint", _endpoint.ToString()); command.Parameters.AddWithValue("@Queue", _queueName); command.Parameters.AddWithValue("@SubQueue", subQueue); command.Parameters.AddWithValue("@Headers", MessagePayload.CompressHeaders(messagePayload.Headers)); command.Parameters.AddWithValue("@ProcessingUntil", DateTime.UtcNow); command.Parameters.AddWithValue("@CreatedAt", messagePayload.SentAt); command.Parameters.AddWithValue("@ExpiresAt", DateTime.UtcNow.AddDays(2)); command.Parameters.Add("@Payload", SqlDbType.VarBinary, -1); command.Parameters["@Payload"].Value = (messagePayload.Data ?? (object)DBNull.Value); command.ExecuteNonQuery(); } }
public void Send(Uri uri, MessagePayload payload) { using (new internalTransactionScope(this)) { using (var command = SqlTransactionContext.Current.Connection.CreateCommand()) { command.CommandTimeout = 60; command.CommandText = "Queue.EnqueueMessage"; command.CommandType = CommandType.StoredProcedure; command.Transaction = SqlTransactionContext.Current.Transaction; command.Parameters.AddWithValue("@Endpoint", uri.ToString()); command.Parameters.AddWithValue("@Queue", uri.GetQueueName()); command.Parameters.AddWithValue("@SubQueue", DBNull.Value); var contents = new RawMessage { CreatedAt = payload.SentAt, Payload = payload.Data, ProcessingUntil = payload.SentAt }; contents.SetHeaders(payload.Headers); command.Parameters.AddWithValue("@CreatedAt", contents.CreatedAt); command.Parameters.AddWithValue("@Payload", contents.Payload); command.Parameters.AddWithValue("@ExpiresAt", DBNull.Value); command.Parameters.AddWithValue("@ProcessingUntil", contents.CreatedAt); command.Parameters.AddWithValue("@Headers", contents.Headers); if (Logger.IsDebugEnabled) { Logger.DebugFormat("Sending message to {0} on {1}. Headers are '{2}'.", uri, uri.GetQueueName(), contents.Headers); } command.ExecuteNonQuery(); } } }
public void SetHeaders(NameValueCollection nameValueCollection) { Headers = MessagePayload.CompressHeaders(nameValueCollection); }