using DotNetCore.CAP;
using Microsoft.AspNetCore.Mvc;

namespace BAP.Cap.Sqlsugar.Demo2.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
        "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
    };

        private readonly ILogger<WeatherForecastController> _logger;

        private ICapPublisher _capBus;

        public WeatherForecastController(ILogger<WeatherForecastController> logger, ICapPublisher capPublisher)
        {
            _logger = logger;
            _capBus = capPublisher;
        }

        [NonAction]
        [CapSubscribe("sample.rabbitmq.sqlserver")]
        public void TestSubscribe(string message)
        {
            Console.WriteLine("收到消息:" + message);
        }

        [NonAction]
        [CapSubscribe("sample.rabbitmq.sqlserver.transaction")]
        public void TestSubscribetransaction(string message)
        {
            Console.WriteLine("收到消息:" + message);




        }

        //[NonAction]
        //[CapSubscribe("sample.rabbitmq.sqlserver")]
        //public void TestPublish(string message)
        //{
        //    Console.WriteLine("收到消息:" + message);
        //}



        [HttpGet(Name = "GetWeatherForecast")]
        public IEnumerable<WeatherForecast> Get()
        {
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
        }
    }
}