public async Task <Guid> CreateAsync(Guid queuId, MessageCrateReqDto message) { using SqlConnection connection = new SqlConnection(this.connectionString); await connection.OpenAsync().ConfigureAwait(false); return(await this.CreateInternal(connection, queuId, message).ConfigureAwait(false)); }
public async Task <IActionResult> CreateMessage(Guid queuId, [FromBody] MessageCrateReqDto message) { this.logger.LogTrace("Call post with message label={0}", message.Label); Guid newMessageId = await this.messageRepository.CreateAsync(queuId, message).ConfigureAwait(false); await this.notificationSender.SendNotificationAsync(queuId, newMessageId).ConfigureAwait(false); MessageDto createdMessage = await this.messageRepository.ReadById(newMessageId).ConfigureAwait(false); return(this.CreatedAtAction(nameof(this.Read), new { queuId = queuId, messageId = newMessageId }, createdMessage)); }
public async Task <PublishResult> Publish(string topic, MessageCrateReqDto message) { using SqlConnection connection = new SqlConnection(this.connectionString); await connection.OpenAsync().ConfigureAwait(false); List <Guid> queuIds = new List <Guid>(25); using (SqlCommand command = connection.CreateCommand()) { command.CommandText = @"SELECT [Id] FROM [dbo].[QueuRecord] WHERE [TopicPattern] IS NOT NULL AND CHARINDEX([TopicPattern], @topic) = 1"; command.CommandType = System.Data.CommandType.Text; command.Parameters.AddWithValue("@topic", topic); using SqlDataReader reader = await command.ExecuteReaderAsync().ConfigureAwait(false); while (await reader.ReadAsync().ConfigureAwait(false)) { queuIds.Add((Guid)reader["Id"]); } } PublishResult result = new PublishResult(); foreach (Guid queuId in queuIds) { Guid messageId = await this.CreateInternal(connection, queuId, message).ConfigureAwait(false); result.CratedMessages.Add(new PublishPair() { MessageId = messageId, QueuId = queuId }); } return(result); }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='queuId'> /// </param> /// <param name='body'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <object> CreateMessageAsync(this IPassiveMQAPI operations, Guid queuId, MessageCrateReqDto body = default(MessageCrateReqDto), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateMessageWithHttpMessagesAsync(queuId, body, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='queuId'> /// </param> /// <param name='body'> /// </param> public static object CreateMessage(this IPassiveMQAPI operations, Guid queuId, MessageCrateReqDto body = default(MessageCrateReqDto)) { return(Task.Factory.StartNew(s => ((IPassiveMQAPI)s).CreateMessageAsync(queuId, body), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
private async Task <Guid> CreateInternal(SqlConnection connection, Guid queuId, MessageCrateReqDto message) { Guid id = Guid.NewGuid(); using SqlCommand command = connection.CreateCommand(); command.CommandText = @"INSERT INTO [dbo].[Message] ([Id], [QueuRecordId], [Created], [Label], [Content], [NextVisible], [RetryCount]) VALUES (@id, @queuRecordId, @created, @label, @content, NULL, 0) "; command.CommandType = System.Data.CommandType.Text; command.Parameters.AddWithValue("@id", id); command.Parameters.AddWithValue("@queuRecordId", queuId); command.Parameters.AddWithValue("@created", this.timeAccessor.UtcNow); command.Parameters.AddWithValue("@label", message.Label.ToSqlValue()); command.Parameters.AddWithValue("@content", message.Content); await command.ExecuteNonQueryAsync().ConfigureAwait(false); return(id); }