Browse Source

code refactor

master
Savorboard 5 years ago
parent
commit
556cb5a0a5
7 changed files with 16 additions and 11 deletions
  1. +1
    -0
      CAP.sln
  2. +1
    -1
      samples/Sample.RabbitMQ.MySql/AppDbContext.cs
  3. +4
    -3
      samples/Sample.RabbitMQ.MySql/Startup.cs
  4. +2
    -1
      src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs
  5. +5
    -3
      src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs
  6. +1
    -1
      src/DotNetCore.CAP/Internal/IMessageSender.Default.cs
  7. +2
    -2
      src/DotNetCore.CAP/Messages/TransportMessage.cs

+ 1
- 0
CAP.sln View File

@@ -108,6 +108,7 @@ Global
{80A84F62-1558-427B-BA74-B47AA8A665B5}.Release|Any CPU.ActiveCfg = Release|Any CPU {80A84F62-1558-427B-BA74-B47AA8A665B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80A84F62-1558-427B-BA74-B47AA8A665B5}.Release|Any CPU.Build.0 = Release|Any CPU {80A84F62-1558-427B-BA74-B47AA8A665B5}.Release|Any CPU.Build.0 = Release|Any CPU
{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Release|Any CPU.ActiveCfg = Release|Any CPU {9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Release|Any CPU.Build.0 = Release|Any CPU {9F3F9BFE-7B6A-4A7A-A6E6-8B517D611873}.Release|Any CPU.Build.0 = Release|Any CPU
{82C403AB-ED68-4084-9A1D-11334F9F08F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {82C403AB-ED68-4084-9A1D-11334F9F08F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU


+ 1
- 1
samples/Sample.RabbitMQ.MySql/AppDbContext.cs View File

@@ -11,7 +11,7 @@ namespace Sample.RabbitMQ.MySql


public class AppDbContext : DbContext public class AppDbContext : DbContext
{ {
public const string ConnectionString = "Server=localhost;Database=testcap;UserId=root;Password=123123;";
public const string ConnectionString = "Server=192.168.2.120;Database=captest;UserId=root;Password=123123;";


public DbSet<Person> Persons { get; set; } public DbSet<Person> Persons { get; set; }




+ 4
- 3
samples/Sample.RabbitMQ.MySql/Startup.cs View File

@@ -1,4 +1,5 @@
using System; using System;
using DotNetCore.CAP.Messages;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@@ -16,12 +17,12 @@ namespace Sample.RabbitMQ.MySql
{ {
x.UseEntityFramework<AppDbContext>(); x.UseEntityFramework<AppDbContext>();
x.UseRabbitMQ("192.168.2.120"); x.UseRabbitMQ("192.168.2.120");
x.UseDashboard();
//x.UseDashboard();
x.FailedRetryCount = 5; x.FailedRetryCount = 5;
x.FailedThresholdCallback = (type, name, content) =>
x.FailedThresholdCallback = (type, msg) =>
{ {
Console.WriteLine( Console.WriteLine(
$@"A message of type {type} failed after executing {x.FailedRetryCount} several times, requiring manual troubleshooting. Message name: {name}, message body: {content}");
$@"A message of type {type} failed after executing {x.FailedRetryCount} several times, requiring manual troubleshooting. Message name: {msg.GetName()}");
}; };
}); });




+ 2
- 1
src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs View File

@@ -3,6 +3,7 @@


using System; using System;
using DotNetCore.CAP.MySql; using DotNetCore.CAP.MySql;
using DotNetCore.CAP.Persistence;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;


@@ -21,7 +22,7 @@ namespace DotNetCore.CAP
public void AddServices(IServiceCollection services) public void AddServices(IServiceCollection services)
{ {
services.AddSingleton<CapStorageMarkerService>(); services.AddSingleton<CapStorageMarkerService>();
//services.AddSingleton<IStorageConnection, MySqlStorageConnection>();
services.AddSingleton<IStorageInitializer, MySqlStorageInitializer>();
services.AddTransient<CapTransactionBase, MySqlCapTransaction>(); services.AddTransient<CapTransactionBase, MySqlCapTransaction>();


//Add MySqlOptions //Add MySqlOptions


+ 5
- 3
src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs View File

@@ -6,8 +6,7 @@ using DotNetCore.CAP;
using DotNetCore.CAP.Abstractions; using DotNetCore.CAP.Abstractions;
using DotNetCore.CAP.Internal; using DotNetCore.CAP.Internal;
using DotNetCore.CAP.Processor; using DotNetCore.CAP.Processor;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using DotNetCore.CAP.Serialization;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;


// ReSharper disable once CheckNamespace // ReSharper disable once CheckNamespace
@@ -58,8 +57,11 @@ namespace Microsoft.Extensions.DependencyInjection
services.TryAddSingleton<TransportCheckProcessor>(); services.TryAddSingleton<TransportCheckProcessor>();


//Sender and Executors //Sender and Executors
services.AddSingleton<IMessageSender, MessageSender>();
services.TryAddSingleton<IMessageSender, MessageSender>();
services.TryAddSingleton<IDispatcher, Dispatcher>(); services.TryAddSingleton<IDispatcher, Dispatcher>();

services.TryAddSingleton<ISerializer, MemorySerializer>();

// Warning: IPublishMessageSender need to inject at extension project. // Warning: IPublishMessageSender need to inject at extension project.
services.TryAddSingleton<ISubscriberExecutor, DefaultSubscriberExecutor>(); services.TryAddSingleton<ISubscriberExecutor, DefaultSubscriberExecutor>();




+ 1
- 1
src/DotNetCore.CAP/Internal/IMessageSender.Default.cs View File

@@ -29,7 +29,7 @@ namespace DotNetCore.CAP.Internal
new DiagnosticListener(CapDiagnosticListenerExtensions.DiagnosticListenerName); new DiagnosticListener(CapDiagnosticListenerExtensions.DiagnosticListenerName);


protected MessageSender( protected MessageSender(
ILogger logger,
ILogger<MessageSender> logger,
IOptions<CapOptions> options, IOptions<CapOptions> options,
IDataStorage dataStorage, IDataStorage dataStorage,
ISerializer serializer, ISerializer serializer,


+ 2
- 2
src/DotNetCore.CAP/Messages/TransportMessage.cs View File

@@ -8,7 +8,7 @@ namespace DotNetCore.CAP.Messages
/// </summary> /// </summary>
public class TransportMessage public class TransportMessage
{ {
public TransportMessage(Dictionary<string, string> headers, byte[] body)
public TransportMessage(IDictionary<string, string> headers, byte[] body)
{ {
Headers = headers ?? throw new ArgumentNullException(nameof(headers)); Headers = headers ?? throw new ArgumentNullException(nameof(headers));
Body = body ?? throw new ArgumentNullException(nameof(body)); Body = body ?? throw new ArgumentNullException(nameof(body));
@@ -17,7 +17,7 @@ namespace DotNetCore.CAP.Messages
/// <summary> /// <summary>
/// Gets the headers of this message /// Gets the headers of this message
/// </summary> /// </summary>
public Dictionary<string, string> Headers { get; }
public IDictionary<string, string> Headers { get; }


/// <summary> /// <summary>
/// Gets the body object of this message /// Gets the body object of this message


Loading…
Cancel
Save