Last active
November 18, 2018 12:10
-
-
Save sergioprates/8775d2ca782b0d61ed0aa999ee985f2e to your computer and use it in GitHub Desktop.
Criando uma API Streaming com .NET Core
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
[HttpPost] | |
public IActionResult Post(Cliente cliente) | |
{ | |
//Fazer o Insert | |
EnviarEvento(cliente, EventoEnum.Insert); | |
return Ok(); | |
} | |
[HttpPut] | |
public IActionResult Put(Cliente cliente) | |
{ | |
//Fazer o Update | |
EnviarEvento(cliente, EventoEnum.Update); | |
return Ok(); | |
} | |
private static async Task EnviarEvento(object dados, EventoEnum evento) | |
{ | |
foreach (var client in _clients) | |
{ | |
string jsonEvento = string.Format("{0}\n", JsonConvert.SerializeObject(new { dados, evento })); | |
await client.WriteAsync(jsonEvento); | |
await client.FlushAsync(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment