Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created July 10, 2025 21:17
Show Gist options
  • Select an option

  • Save dcomartin/20af7567b3e16c82bfa0c5b353d1ce52 to your computer and use it in GitHub Desktop.

Select an option

Save dcomartin/20af7567b3e16c82bfa0c5b353d1ce52 to your computer and use it in GitHub Desktop.
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] ITransactionalSession session)
{
var id = Guid.NewGuid().ToString();
await _dataContext.MyEntities.AddAsync(new MyEntity { Id = id, Processed = false });
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