// SAMPLE: ExplicitOutboxUsage public static async Task explicit_usage( CreateItemCommand command, IDocumentStore store, IMessageContext context) { var item = new Item { Name = command.Name }; using (var session = store.LightweightSession()) { // This tells the current Jasper message context // to persist outgoing messages with this // Marten session and to delay actually sending // out the outgoing messages until the session // has been committed await context.EnlistInTransaction(session); session.Store(item); // Registering an outgoing message, nothing is // actually "sent" yet though await context.Publish(new ItemCreatedEvent { Item = item }); // Commit all the queued up document and outgoing messages // to the underlying Postgresql database. await session.SaveChangesAsync(); } }
public void Handle(CreateItemCommand command) { var item = new Item { Name = command.Name }; _session.Store(item); _session.SaveChanges(); }
public static ItemCreatedEvent Handle(CreateItemCommand command, IDocumentSession session) { // This Item document and the outgoing ItemCreatedEvent // message being published will be persisted in // the same native Postgresql transaction var item = new Item { Name = command.Name }; session.Store(item); // The outgoing message here is persisted with Marten // as part of the same transaction return(new ItemCreatedEvent { Item = item }); }
public async Task run_locally(IMessageContext context) { var command = new CreateItemCommand(); // Run locally right now await context.Invoke(command); // Run in the background, let Jasper decide if the message should be durable await context.Enqueue(command); // or fire-and-forget await context.EnqueueLightweight(command); // or durably await context.EnqueueDurably(command); // or run it in the future await context.Schedule(command, 5.Minutes()); // or at a specific time await context.Schedule(command, DateTime.Today.AddHours(23)); }