Last active
May 29, 2023 05:41
-
-
Save syedharoonmca/098fc1098cce1e47dabddf31673bb126 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text.Json; | |
using Azure.Messaging.ServiceBus; | |
using Microsoft.AspNetCore.Mvc; | |
namespace TodoApi3.Controllers; | |
[ApiController] | |
[Route("[controller]")] | |
public class WeatherForecastController : ControllerBase | |
{ | |
private static readonly string[] Summaries = new[] | |
{ | |
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | |
}; | |
private readonly ILogger<WeatherForecastController> _logger; | |
public WeatherForecastController(ILogger<WeatherForecastController> logger) | |
{ | |
_logger = logger; | |
} | |
[HttpGet(Name = "GetWeatherForecast")] | |
public IEnumerable<WeatherForecast> Get() | |
{ | |
return Enumerable.Range(1, 5).Select(index => new WeatherForecast | |
{ | |
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), | |
TemperatureC = Random.Shared.Next(-20, 55), | |
Summary = Summaries[Random.Shared.Next(Summaries.Length)] | |
}) | |
.ToArray(); | |
} | |
[HttpPost] | |
public async Task Post(WeatherForecast data) | |
{ | |
var connectionString = "Endpoint=sb://servicebusnms.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=swg5kLjZ1VKRuuRwKgNTh0fuzFwJcXKTL+ASbCUfwiA="; | |
var client = new ServiceBusClient(connectionString); | |
var sender =client.CreateSender("add-weather-data"); | |
var body=JsonSerializer.Serialize(data); | |
var message=new ServiceBusMessage(body); | |
await sender.SendMessageAsync(message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment