From e7be86f09f972e7cdcc7d8cf3610daf6cb8048f1 Mon Sep 17 00:00:00 2001 From: wanggang Date: Thu, 14 Apr 2022 10:42:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0BPA.CAP=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BAP.Cap.Sqlsugar.Demo1.csproj | 19 +++++ .../Controllers/WeatherForecastController.cs | 81 +++++++++++++++++++ BAP.Cap.Sqlsugar.Demo1/Entity/Num.cs | 12 +++ BAP.Cap.Sqlsugar.Demo1/Program.cs | 53 ++++++++++++ BAP.Cap.Sqlsugar.Demo1/WeatherForecast.cs | 13 +++ .../appsettings.Development.json | 8 ++ BAP.Cap.Sqlsugar.Demo1/appsettings.json | 19 +++++ .../BAP.Cap.Sqlsugar.Demo2.csproj | 18 +++++ .../Controllers/WeatherForecastController.cs | 64 +++++++++++++++ BAP.Cap.Sqlsugar.Demo2/Entity/Num.cs | 12 +++ BAP.Cap.Sqlsugar.Demo2/Program.cs | 42 ++++++++++ BAP.Cap.Sqlsugar.Demo2/WeatherForecast.cs | 13 +++ .../appsettings.Development.json | 8 ++ BAP.Cap.Sqlsugar.Demo2/appsettings.json | 10 +++ BAP.Cap.Sqlsugar/BAP.Cap.Sqlsugar.csproj | 22 +++++ BAP.Cap.Sqlsugar/CapExtensions.cs | 77 ++++++++++++++++++ BPA.CAP/BPA - Backup.CAP.csproj | 19 +++++ BPA.CAP/BPA.CAP.csproj | 25 ++++++ BPA.CAP/CapExtensions.cs | 75 +++++++++++++++++ BPA.CAP/Settings/CapSettings.cs | 18 +++++ BPA.CAP/Settings/RabbitmqSettings.cs | 27 +++++++ CAP.sln | 32 +++++++- samples/Sample.RabbitMQ.MySql/Startup.cs | 7 +- 23 files changed, 672 insertions(+), 2 deletions(-) create mode 100644 BAP.Cap.Sqlsugar.Demo1/BAP.Cap.Sqlsugar.Demo1.csproj create mode 100644 BAP.Cap.Sqlsugar.Demo1/Controllers/WeatherForecastController.cs create mode 100644 BAP.Cap.Sqlsugar.Demo1/Entity/Num.cs create mode 100644 BAP.Cap.Sqlsugar.Demo1/Program.cs create mode 100644 BAP.Cap.Sqlsugar.Demo1/WeatherForecast.cs create mode 100644 BAP.Cap.Sqlsugar.Demo1/appsettings.Development.json create mode 100644 BAP.Cap.Sqlsugar.Demo1/appsettings.json create mode 100644 BAP.Cap.Sqlsugar.Demo2/BAP.Cap.Sqlsugar.Demo2.csproj create mode 100644 BAP.Cap.Sqlsugar.Demo2/Controllers/WeatherForecastController.cs create mode 100644 BAP.Cap.Sqlsugar.Demo2/Entity/Num.cs create mode 100644 BAP.Cap.Sqlsugar.Demo2/Program.cs create mode 100644 BAP.Cap.Sqlsugar.Demo2/WeatherForecast.cs create mode 100644 BAP.Cap.Sqlsugar.Demo2/appsettings.Development.json create mode 100644 BAP.Cap.Sqlsugar.Demo2/appsettings.json create mode 100644 BAP.Cap.Sqlsugar/BAP.Cap.Sqlsugar.csproj create mode 100644 BAP.Cap.Sqlsugar/CapExtensions.cs create mode 100644 BPA.CAP/BPA - Backup.CAP.csproj create mode 100644 BPA.CAP/BPA.CAP.csproj create mode 100644 BPA.CAP/CapExtensions.cs create mode 100644 BPA.CAP/Settings/CapSettings.cs create mode 100644 BPA.CAP/Settings/RabbitmqSettings.cs diff --git a/BAP.Cap.Sqlsugar.Demo1/BAP.Cap.Sqlsugar.Demo1.csproj b/BAP.Cap.Sqlsugar.Demo1/BAP.Cap.Sqlsugar.Demo1.csproj new file mode 100644 index 0000000..19dd5d7 --- /dev/null +++ b/BAP.Cap.Sqlsugar.Demo1/BAP.Cap.Sqlsugar.Demo1.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/BAP.Cap.Sqlsugar.Demo1/Controllers/WeatherForecastController.cs b/BAP.Cap.Sqlsugar.Demo1/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..5f101b7 --- /dev/null +++ b/BAP.Cap.Sqlsugar.Demo1/Controllers/WeatherForecastController.cs @@ -0,0 +1,81 @@ +using BAP.Cap.Sqlsugar.Demo1.Entity; +using DotNetCore.CAP; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Data.SqlClient; +using SqlSugar; +using System.Data; + +namespace BAP.Cap.Sqlsugar.Demo1.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 _logger; + + private ICapPublisher _capBus; + private SqlSugarScope _sqlSugarScope; + public WeatherForecastController(ILogger logger, ICapPublisher capPublisher, SqlSugarScope sqlSugarScope) + { + _sqlSugarScope= sqlSugarScope; + _logger = logger; + _capBus = capPublisher; + } + + [HttpGet,Route("TestPublish")] + public async Task TestPublish() + { + await _capBus.PublishAsync("sample.rabbitmq.sqlserver", DateTime.Now); + } + + [HttpGet,Route("~/adonet/transaction")] + public IActionResult AdonetWithTransaction() + { + //_sqlSugarScope.ScopedContext.BeginTran + //_sqlSugarScope.GetConnection(1) + //_sqlSugarScope.ScopedContext.UseTran(). + //IDbConnection. + + using (var connection =(SqlConnection) _sqlSugarScope.Ado.Connection ) + { + using (var transaction = connection.BeginTransaction(_capBus, false)) + { + if (connection.State != ConnectionState.Open) + { + connection.Open(); + } + _sqlSugarScope.Ado.Transaction =transaction; + //_sqlSugarScope.Insertable(new Num() + //{ + // Id = 1, + // Number1 = 2 + //}).ExecuteCommand(); + + + _capBus.Publish("sample.rabbitmq.sqlserver.transaction", "执行"); + transaction.Commit(); + } + } + return Ok(); + } + + + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable 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(); + } + } +} \ No newline at end of file diff --git a/BAP.Cap.Sqlsugar.Demo1/Entity/Num.cs b/BAP.Cap.Sqlsugar.Demo1/Entity/Num.cs new file mode 100644 index 0000000..6b82394 --- /dev/null +++ b/BAP.Cap.Sqlsugar.Demo1/Entity/Num.cs @@ -0,0 +1,12 @@ +锘縰sing SqlSugar; + +namespace BAP.Cap.Sqlsugar.Demo1.Entity +{ + [SugarTable("Num")] + public class Num + { + public int Id { get; set; } + + public int Number1 { get; set; } + } +} diff --git a/BAP.Cap.Sqlsugar.Demo1/Program.cs b/BAP.Cap.Sqlsugar.Demo1/Program.cs new file mode 100644 index 0000000..8314f53 --- /dev/null +++ b/BAP.Cap.Sqlsugar.Demo1/Program.cs @@ -0,0 +1,53 @@ +using BAP.CAP; +using BPA.CAP.Settings; +using BPA.Component.ApolloClient; +using SqlSugar; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddApolloConfiguration(builder); + +builder.Services.AddCapConfiguration(builder.Configuration,new CapSettings +{ + FailedThresholdCallback = fail => + { + var mess = fail.Message; + } +}); + +//SqlSugarScope db = new SqlSugarScope(new ConnectionConfig() +//{ +// ConnectionString = builder.Configuration.GetSection("ConnectionStrings").Value,//连接符字串 +// DbType = DbType.SqlServer,//数据库类型 +// IsAutoCloseConnection = true //不设成true要手动close +//} +//); +//db.Aop.OnLogExecuted = (sql, pars) => +//{ + +//}; +//builder.Services.AddSingleton(db); +builder.Services.AddControllers(); + +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(c => +{ + c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); +}); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/BAP.Cap.Sqlsugar.Demo1/WeatherForecast.cs b/BAP.Cap.Sqlsugar.Demo1/WeatherForecast.cs new file mode 100644 index 0000000..801caf3 --- /dev/null +++ b/BAP.Cap.Sqlsugar.Demo1/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace BAP.Cap.Sqlsugar.Demo1 +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} \ No newline at end of file diff --git a/BAP.Cap.Sqlsugar.Demo1/appsettings.Development.json b/BAP.Cap.Sqlsugar.Demo1/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/BAP.Cap.Sqlsugar.Demo1/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/BAP.Cap.Sqlsugar.Demo1/appsettings.json b/BAP.Cap.Sqlsugar.Demo1/appsettings.json new file mode 100644 index 0000000..ed559c4 --- /dev/null +++ b/BAP.Cap.Sqlsugar.Demo1/appsettings.json @@ -0,0 +1,19 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + // "ConnectionStrings": "Data Source=10.2.1.21;Initial Catalog=demo1;MultipleActiveResultSets=true;Persist Security Info=True;User ID=sa;Password=BapAdmin123456.;" + "ApolloClientSettings": { + "Host": "http://10.2.1.21", + "Port": 28080, + "Env": "Dev", + "CommonNameSpace": "DEV.Config", + "ClientNameSpace": "application", + "AppId": "dev1_order" + } + +} diff --git a/BAP.Cap.Sqlsugar.Demo2/BAP.Cap.Sqlsugar.Demo2.csproj b/BAP.Cap.Sqlsugar.Demo2/BAP.Cap.Sqlsugar.Demo2.csproj new file mode 100644 index 0000000..630f26c --- /dev/null +++ b/BAP.Cap.Sqlsugar.Demo2/BAP.Cap.Sqlsugar.Demo2.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/BAP.Cap.Sqlsugar.Demo2/Controllers/WeatherForecastController.cs b/BAP.Cap.Sqlsugar.Demo2/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..7f5eded --- /dev/null +++ b/BAP.Cap.Sqlsugar.Demo2/Controllers/WeatherForecastController.cs @@ -0,0 +1,64 @@ +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 _logger; + + private ICapPublisher _capBus; + + public WeatherForecastController(ILogger 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 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(); + } + } +} \ No newline at end of file diff --git a/BAP.Cap.Sqlsugar.Demo2/Entity/Num.cs b/BAP.Cap.Sqlsugar.Demo2/Entity/Num.cs new file mode 100644 index 0000000..3a8fba5 --- /dev/null +++ b/BAP.Cap.Sqlsugar.Demo2/Entity/Num.cs @@ -0,0 +1,12 @@ +锘縰sing SqlSugar; + +namespace BAP.Cap.Sqlsugar.Demo2.Entity +{ + [SugarTable("Num")] + public class Num + { + public int Id { get; set; } + + public int Number2 { get; set; } + } +} diff --git a/BAP.Cap.Sqlsugar.Demo2/Program.cs b/BAP.Cap.Sqlsugar.Demo2/Program.cs new file mode 100644 index 0000000..bb21066 --- /dev/null +++ b/BAP.Cap.Sqlsugar.Demo2/Program.cs @@ -0,0 +1,42 @@ +using BAP.Cap.Sqlsugar; +using SqlSugar; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddCapConfiguration(builder.Configuration); + +SqlSugarScope db = new SqlSugarScope(new ConnectionConfig() +{ + ConnectionString = builder.Configuration.GetSection("ConnectionStrings").Value,//连接符字串 + DbType = DbType.SqlServer,//数据库类型 + IsAutoCloseConnection = true //不设成true要手动close +} +); +db.Aop.OnLogExecuted = (sql, pars) => +{ + +}; +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(c => +{ + c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); +}); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/BAP.Cap.Sqlsugar.Demo2/WeatherForecast.cs b/BAP.Cap.Sqlsugar.Demo2/WeatherForecast.cs new file mode 100644 index 0000000..710fbc8 --- /dev/null +++ b/BAP.Cap.Sqlsugar.Demo2/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace BAP.Cap.Sqlsugar.Demo2 +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} \ No newline at end of file diff --git a/BAP.Cap.Sqlsugar.Demo2/appsettings.Development.json b/BAP.Cap.Sqlsugar.Demo2/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/BAP.Cap.Sqlsugar.Demo2/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/BAP.Cap.Sqlsugar.Demo2/appsettings.json b/BAP.Cap.Sqlsugar.Demo2/appsettings.json new file mode 100644 index 0000000..772fb44 --- /dev/null +++ b/BAP.Cap.Sqlsugar.Demo2/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "ConnectionStrings": "Data Source=10.2.1.21;Initial Catalog=demo2;MultipleActiveResultSets=true;Persist Security Info=True;User ID=sa;Password=BapAdmin123456.;" +} diff --git a/BAP.Cap.Sqlsugar/BAP.Cap.Sqlsugar.csproj b/BAP.Cap.Sqlsugar/BAP.Cap.Sqlsugar.csproj new file mode 100644 index 0000000..cbef943 --- /dev/null +++ b/BAP.Cap.Sqlsugar/BAP.Cap.Sqlsugar.csproj @@ -0,0 +1,22 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + diff --git a/BAP.Cap.Sqlsugar/CapExtensions.cs b/BAP.Cap.Sqlsugar/CapExtensions.cs new file mode 100644 index 0000000..6ecb1db --- /dev/null +++ b/BAP.Cap.Sqlsugar/CapExtensions.cs @@ -0,0 +1,77 @@ +锘縰sing Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Encodings.Web; +using System.Text.Unicode; +using System.Threading.Tasks; + +namespace BAP.Cap.Sqlsugar +{ + /// + /// CAP鎵╁睍 + /// + public static class CapExtensions + { + + public static IServiceCollection AddCapConfiguration(this IServiceCollection services, IConfiguration configuration) + { + + var dbConfig= configuration.GetSection("ConnectionStrings").Value; + // }; + services.AddCap(x => { + x.UseSqlServer(dbConfig); + x.UseRabbitMQ(options => + { + options.HostName = "10.2.1.21"; + options.UserName = "guest"; + options.Password = "guest"; + }); + x.UseDashboard(); + x.FailedRetryCount = 5; + x.FailedThresholdCallback = failed => + { + //var logger = failed.ServiceProvider.GetService>(); + //logger.LogError($@"A message of type {failed.MessageType} failed after executing {x.FailedRetryCount} several times, + // requiring manual troubleshooting. Message name: {failed.Message.GetName()}"); + }; + x.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); + }); + + // db.ScopedContext + //, db => + // { + // //(A)鍏ㄥ眬鐢熸晥閰嶇疆鐐 + // //璋冭瘯SQL浜嬩欢锛屽彲浠ュ垹鎺 + // db.Aop.OnLogExecuting = (sql, pars) => + // { + // Console.WriteLine(sql);//杈撳嚭sql,鏌ョ湅鎵цsql + // }; + // } + + + // ApolloClientSettings metaServerSettings = new ApolloClientSettings(); + // builder.Configuration.GetSection(nameof(ApolloClientSettings)).Bind(metaServerSettings); + // services.AddSingleton(metaServerSettings); + //#pragma warning disable CS8601 // 寮曠敤绫诲瀷璧嬪煎彲鑳戒负 null銆 + //#pragma warning disable CS8604 // 寮曠敤绫诲瀷鍙傛暟鍙兘涓 null銆 + // var apollo = builder.Configuration.AddApollo(new ApolloOptions + // { + // AppId = metaServerSettings.AppId, + // MetaServer = metaServerSettings.Host + ":" + metaServerSettings.Port, + // Env = metaServerSettings.Env, + // }).AddNamespace(metaServerSettings.CommonNameSpace).AddNamespace(metaServerSettings.ClientNameSpace); + //#pragma warning restore CS8604 // 寮曠敤绫诲瀷鍙傛暟鍙兘涓 null銆 + //#pragma warning restore CS8601 // 寮曠敤绫诲瀷璧嬪煎彲鑳戒负 null銆 + + return services; + } + + + } +} diff --git a/BPA.CAP/BPA - Backup.CAP.csproj b/BPA.CAP/BPA - Backup.CAP.csproj new file mode 100644 index 0000000..cc46df0 --- /dev/null +++ b/BPA.CAP/BPA - Backup.CAP.csproj @@ -0,0 +1,19 @@ + + + net6.0 + enable + enable + 1.0.1 + + + + + + + + + + + + + \ No newline at end of file diff --git a/BPA.CAP/BPA.CAP.csproj b/BPA.CAP/BPA.CAP.csproj new file mode 100644 index 0000000..e40af8a --- /dev/null +++ b/BPA.CAP/BPA.CAP.csproj @@ -0,0 +1,25 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + diff --git a/BPA.CAP/CapExtensions.cs b/BPA.CAP/CapExtensions.cs new file mode 100644 index 0000000..e0b2e2e --- /dev/null +++ b/BPA.CAP/CapExtensions.cs @@ -0,0 +1,75 @@ +锘 +using BPA.CAP.Settings; +using DotNetCore.CAP; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Encodings.Web; +using System.Text.Unicode; +using System.Threading.Tasks; + +namespace BAP.CAP +{ + /// + /// CAP鎵╁睍 + /// + public static class CapExtensions + { + + public static IServiceCollection AddCapConfiguration(this IServiceCollection services, IConfiguration configuration, CapSettings capSettings=null) + { + + RabbitmqSettings rabbitmqSettings = new RabbitmqSettings(); + rabbitmqSettings= JsonConvert.DeserializeObject(configuration.GetSection("rabbitmq_config").Value); + + if(capSettings==null) capSettings = new CapSettings(); + var dbConfig= configuration.GetSection("sqlserver_config").Value; + services.AddCap(x => { + x.UseSqlServer(configuration.GetSection("sqlserver_config").Value); + x.UseRabbitMQ(options => + { + options.HostName = rabbitmqSettings.HostName;// "10.2.1.21"; + options.UserName = rabbitmqSettings.UserName;// "guest"; + options.Password = rabbitmqSettings.Password;// "guest"; + }); + x.UseDashboard(); + x.FailedRetryCount = 5; + x.FailedThresholdCallback+= capSettings.FailedThresholdCallback; + x.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); + }); + services.AddSingleton(capSettings); + // db.ScopedContext + //, db => + // { + // //(A)鍏ㄥ眬鐢熸晥閰嶇疆鐐 + // //璋冭瘯SQL浜嬩欢锛屽彲浠ュ垹鎺 + // db.Aop.OnLogExecuting = (sql, pars) => + // { + // Console.WriteLine(sql);//杈撳嚭sql,鏌ョ湅鎵цsql + // }; + // } + + + // ApolloClientSettings metaServerSettings = new ApolloClientSettings(); + // builder.Configuration.GetSection(nameof(ApolloClientSettings)).Bind(metaServerSettings); + // services.AddSingleton(metaServerSettings); + //#pragma warning disable CS8601 // 寮曠敤绫诲瀷璧嬪煎彲鑳戒负 null銆 + //#pragma warning disable CS8604 // 寮曠敤绫诲瀷鍙傛暟鍙兘涓 null銆 + // var apollo = builder.Configuration.AddApollo(new ApolloOptions + // { + // AppId = metaServerSettings.AppId, + // MetaServer = metaServerSettings.Host + ":" + metaServerSettings.Port, + // Env = metaServerSettings.Env, + // }).AddNamespace(metaServerSettings.CommonNameSpace).AddNamespace(metaServerSettings.ClientNameSpace); + //#pragma warning restore CS8604 // 寮曠敤绫诲瀷鍙傛暟鍙兘涓 null銆 + //#pragma warning restore CS8601 // 寮曠敤绫诲瀷璧嬪煎彲鑳戒负 null銆 + return services; + } + + + } +} diff --git a/BPA.CAP/Settings/CapSettings.cs b/BPA.CAP/Settings/CapSettings.cs new file mode 100644 index 0000000..aa715bb --- /dev/null +++ b/BPA.CAP/Settings/CapSettings.cs @@ -0,0 +1,18 @@ +锘縰sing DotNetCore.CAP.Messages; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.CAP.Settings +{ + + /// + /// cap閰嶇疆 + /// + public class CapSettings + { + public Action? FailedThresholdCallback { get; set; } + } +} diff --git a/BPA.CAP/Settings/RabbitmqSettings.cs b/BPA.CAP/Settings/RabbitmqSettings.cs new file mode 100644 index 0000000..ab02bc7 --- /dev/null +++ b/BPA.CAP/Settings/RabbitmqSettings.cs @@ -0,0 +1,27 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.CAP.Settings +{ + public class RabbitmqSettings + { + /// + /// The host to connect to. + /// If you want connect to the cluster, you can assign like 鈥192.168.1.111,192.168.1.112鈥 + /// + public string HostName { get; set; } + + /// + /// Password to use when authenticating to the server. + /// + public string Password { get; set; } + + /// + /// Username to use when authenticating to the server. + /// + public string UserName { get; set; } + } +} diff --git a/CAP.sln b/CAP.sln index e7107e6..fbd6081 100644 --- a/CAP.sln +++ b/CAP.sln @@ -86,7 +86,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.RabbitMQ.SqlServer.D EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetCore.CAP.OpenTelemetry", "src\DotNetCore.CAP.OpenTelemetry\DotNetCore.CAP.OpenTelemetry.csproj", "{83DDB126-A00B-4064-86E7-568322CA67EC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.AzureServiceBus.InMemory", "samples\Sample.AzureServiceBus.InMemory\Sample.AzureServiceBus.InMemory.csproj", "{0C734FB2-7D75-4FF3-B564-1E50E6280B14}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.AzureServiceBus.InMemory", "samples\Sample.AzureServiceBus.InMemory\Sample.AzureServiceBus.InMemory.csproj", "{0C734FB2-7D75-4FF3-B564-1E50E6280B14}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "bpa", "bpa", "{DF0DD539-DC9F-45F2-9A40-2FEAECCA8A32}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BAP.Cap.Sqlsugar", "BAP.Cap.Sqlsugar\BAP.Cap.Sqlsugar.csproj", "{68033006-2247-4F29-9734-3C243D176B90}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BAP.Cap.Sqlsugar.Demo1", "BAP.Cap.Sqlsugar.Demo1\BAP.Cap.Sqlsugar.Demo1.csproj", "{9DB77AD7-1704-420B-891E-56D208B18C2F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BAP.Cap.Sqlsugar.Demo2", "BAP.Cap.Sqlsugar.Demo2\BAP.Cap.Sqlsugar.Demo2.csproj", "{89D860D2-7021-4E61-983A-9731A67FD948}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BPA.CAP", "BPA.CAP\BPA.CAP.csproj", "{B980C896-4CA9-4AC4-AFED-5A8D752FB005}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -214,6 +224,22 @@ Global {0C734FB2-7D75-4FF3-B564-1E50E6280B14}.Debug|Any CPU.Build.0 = Debug|Any CPU {0C734FB2-7D75-4FF3-B564-1E50E6280B14}.Release|Any CPU.ActiveCfg = Release|Any CPU {0C734FB2-7D75-4FF3-B564-1E50E6280B14}.Release|Any CPU.Build.0 = Release|Any CPU + {68033006-2247-4F29-9734-3C243D176B90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {68033006-2247-4F29-9734-3C243D176B90}.Debug|Any CPU.Build.0 = Debug|Any CPU + {68033006-2247-4F29-9734-3C243D176B90}.Release|Any CPU.ActiveCfg = Release|Any CPU + {68033006-2247-4F29-9734-3C243D176B90}.Release|Any CPU.Build.0 = Release|Any CPU + {9DB77AD7-1704-420B-891E-56D208B18C2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9DB77AD7-1704-420B-891E-56D208B18C2F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9DB77AD7-1704-420B-891E-56D208B18C2F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9DB77AD7-1704-420B-891E-56D208B18C2F}.Release|Any CPU.Build.0 = Release|Any CPU + {89D860D2-7021-4E61-983A-9731A67FD948}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89D860D2-7021-4E61-983A-9731A67FD948}.Debug|Any CPU.Build.0 = Debug|Any CPU + {89D860D2-7021-4E61-983A-9731A67FD948}.Release|Any CPU.ActiveCfg = Release|Any CPU + {89D860D2-7021-4E61-983A-9731A67FD948}.Release|Any CPU.Build.0 = Release|Any CPU + {B980C896-4CA9-4AC4-AFED-5A8D752FB005}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B980C896-4CA9-4AC4-AFED-5A8D752FB005}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B980C896-4CA9-4AC4-AFED-5A8D752FB005}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B980C896-4CA9-4AC4-AFED-5A8D752FB005}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -249,6 +275,10 @@ Global {DCDF58E8-F823-4F04-9F8C-E8076DC16A68} = {3A6B6931-A123-477A-9469-8B468B5385AF} {83DDB126-A00B-4064-86E7-568322CA67EC} = {9B2AE124-6636-4DE9-83A3-70360DABD0C4} {0C734FB2-7D75-4FF3-B564-1E50E6280B14} = {3A6B6931-A123-477A-9469-8B468B5385AF} + {68033006-2247-4F29-9734-3C243D176B90} = {DF0DD539-DC9F-45F2-9A40-2FEAECCA8A32} + {9DB77AD7-1704-420B-891E-56D208B18C2F} = {DF0DD539-DC9F-45F2-9A40-2FEAECCA8A32} + {89D860D2-7021-4E61-983A-9731A67FD948} = {DF0DD539-DC9F-45F2-9A40-2FEAECCA8A32} + {B980C896-4CA9-4AC4-AFED-5A8D752FB005} = {DF0DD539-DC9F-45F2-9A40-2FEAECCA8A32} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2E70565D-94CF-40B4-BFE1-AC18D5F736AB} diff --git a/samples/Sample.RabbitMQ.MySql/Startup.cs b/samples/Sample.RabbitMQ.MySql/Startup.cs index 6b31ef5..7690c10 100644 --- a/samples/Sample.RabbitMQ.MySql/Startup.cs +++ b/samples/Sample.RabbitMQ.MySql/Startup.cs @@ -14,7 +14,12 @@ namespace Sample.RabbitMQ.MySql services.AddCap(x => { x.UseEntityFramework(); - x.UseRabbitMQ("localhost"); + x.UseRabbitMQ(options => + { + options.HostName = "10.2.1.21"; + options.UserName = "guest"; + options.Password = "guest"; + }); x.UseDashboard(); x.FailedRetryCount = 5; x.FailedThresholdCallback = failed =>