// SAMPLE: what-else-can-the-in-memory-bus-do public static async Task WhatElseCanItDo(RegisterUser user, ICommandBus bus) { // Execute the command *right this instance*, // and because we didn't ask for the UserRegistered event, // Jasper enqueues *that* message for execution await bus.Invoke(user); // Enqueues the command locally for execution // on a background thread await bus.Enqueue(user); // Enqueues the command locally for execution, // but specify a pre-configured worker queue // name if you want to give some messages a // higher or lower priority await bus.Enqueue(user, "important"); // Enqueue the command locally, but first persist // the command to durable storage for "guaranteed // execution" await bus.EnqueueDurably(user); // Schedule the command to be executed in 5 minutes await bus.Schedule(user, 5.Minutes()); // Schedule the command to be executed at 1AM tomorrow await bus.Schedule(user, DateTimeOffset.UtcNow.Date.AddDays(1).AddHours(1)); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); await _bus.Enqueue(new CreateItemCommand { Name = $"Item at {DateTimeOffset.Now}" }); await Task.Delay(2000, stoppingToken); } }
// SAMPLE: enqueue-locally public static async Task enqueue_locally(ICommandBus bus) { // Enqueue a message to the local worker queues await bus.Enqueue(new Message1()); }