using DotNetCore.CAP; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Savorboard.CAP.InMemoryMessageQueue; namespace DS.Module.Nuget { /// /// https://cap.dotnetcore.xyz/user-guide/zh/cap/configuration/ /// internal class captest { public void ConfigureServices(IServiceCollection services) { services.AddCap(x => { x.UseInMemoryStorage(); x.UseInMemoryMessageQueue(); }); } public class PublishController : Controller { [Route("~/send")] public IActionResult SendMessage([FromServices] ICapPublisher capBus) { capBus.Publish("test.show.time", DateTime.Now); return Ok(); } } /// /// 发送延时消息 /// public class PublishyController : Controller { [Route("~/send/delay")] public IActionResult SendDelayMessage([FromServices] ICapPublisher capBus) { capBus.PublishDelay(TimeSpan.FromSeconds(100), "test.show.time", DateTime.Now); return Ok(); } } /// /// 处理消息 /// public class ConsumerController : Controller { [NonAction] [CapSubscribe("test.show.time")] public void ReceiveMessage(DateTime time) { Console.WriteLine("message time is:" + time); } } } }