-
-
Save dcomartin/c8d5751a67cc2d4f174b2d84bb97d86f to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
| using System.Threading.Tasks; | |
| using Microsoft.AspNetCore.Mvc; | |
| using NServiceBus; | |
| using NServiceBus.TransactionalSession; | |
| [ApiController] | |
| [Route("")] | |
| public class SendMessageController : Controller | |
| { | |
| private readonly MyDataContext _dataContext; | |
| public SendMessageController(MyDataContext dataContext) | |
| { | |
| _dataContext = dataContext; | |
| } | |
| [HttpGet("/")] | |
| public async Task<string> Get([FromServices] IMessageSession session) | |
| { | |
| var id = Guid.NewGuid().ToString(); | |
| await _dataContext.MyEntities.AddAsync(new MyEntity { Id = id, Processed = false }); | |
| await _dataContext.SaveChangesAsync(); | |
| throw new Exception("... and boom goes the dynamite."); | |
| // The rest of this code path will never occur | |
| var message = new MyMessage { EntityId = id }; | |
| await session.SendLocal(message); | |
| return $"Message with entity ID '{id}' sent to endpoint"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment