예제 #1
0
 protected static Task <TResult> SendAsync <TQueueProcessor, TResult>(TMessageParam messageParams, string subscription,
                                                                      Func <TResult> onSent,
                                                                      Func <string, TResult> onFailure)
     where TQueueProcessor : QueueProcessor <TMessageParam>
 {
     return(Web.Configuration.Settings.GetString(
                Security.SessionServer.Configuration.AppSettings.ServiceBusConnectionString,
                async serviceBusConnectionString =>
     {
         var message = new Microsoft.Azure.ServiceBus.Message();
         EncodeMessageParams(message.UserProperties, messageParams);
         message.UserProperties[MESSAGE_PROPERTY_KEY_MESSAGE_NAME] = subscription;
         var sendClient = new Microsoft.Azure.ServiceBus.QueueClient(serviceBusConnectionString, subscription);
         try
         {
             await sendClient.SendAsync(message);
             return onSent();
         }
         catch (Exception ex)
         {
             return onFailure(ex.Message);
         }
         finally
         {
             await sendClient.CloseAsync();
         }
     },
                onFailure.AsAsyncFunc()));
 }
예제 #2
0
        public async Task <IActionResult> SendEmail([FromServices] IOptions <ServiceBusOptions> options, SendEmailRequest sendEmailRequest)
        {
            var email          = Newtonsoft.Json.JsonConvert.SerializeObject(sendEmailRequest);
            var messagecontent = System.Text.Encoding.UTF8.GetBytes(email);
            var qc             = new Microsoft.Azure.ServiceBus.QueueClient(options.Value.ConnectionString, "email-input");
            await qc.SendAsync(new Microsoft.Azure.ServiceBus.Message(messagecontent));

            // var random = new Random();
            // Thread.Sleep(random.Next(3000, 8000));

            // if(random.Next(0, 1) > 0)
            //     return StatusCode(InternalServerErrorHttpStatusCode);

            return(RedirectToAction(nameof(Index)));
        }
예제 #3
0
        public async Task SendMessage(string blobName)
        {
            var message = new Microsoft.Azure.ServiceBus.Message(Encoding.UTF8.GetBytes(blobName));

            await _queueClient.SendAsync(message);
        }