From 48453f191a33818e6b933198ceebbccb80b448c7 Mon Sep 17 00:00:00 2001 From: catcherwong Date: Mon, 11 Feb 2019 15:45:38 +0800 Subject: [PATCH 1/8] :children_crossing: Modify section name of configuration. --- .../Configurations/EasyCachingOptionsExtensions.cs | 3 ++- .../Configurations/EasyCachingOptionsExtensions.cs | 3 ++- src/EasyCaching.Core/Internal/EasyCachingConstValue.cs | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs index a58a6829..76ae31ee 100644 --- a/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs @@ -1,6 +1,7 @@ namespace EasyCaching.Bus.RabbitMQ { using System; + using EasyCaching.Core; using EasyCaching.Core.Configurations; using Microsoft.Extensions.Configuration; @@ -33,7 +34,7 @@ public static EasyCachingOptions WithRabbitMQBus(this EasyCachingOptions options /// Options. /// Configuration. /// Section name. - public static EasyCachingOptions WithRabbitMQBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = "rabbitmqbus") + public static EasyCachingOptions WithRabbitMQBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = EasyCachingConstValue.RabbitMQBusSection) { var dbConfig = configuration.GetSection(sectionName); var busOptions = new RabbitMQBusOptions(); diff --git a/src/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs index 0c5192e5..c5e28540 100644 --- a/src/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs @@ -1,6 +1,7 @@ namespace EasyCaching.Bus.Redis { using System; + using EasyCaching.Core; using EasyCaching.Core.Configurations; using Microsoft.Extensions.Configuration; @@ -33,7 +34,7 @@ public static EasyCachingOptions WithRedisBus(this EasyCachingOptions options, A /// Options. /// Configuration. /// Section name. - public static EasyCachingOptions WithRedisBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = "redisbus") + public static EasyCachingOptions WithRedisBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = EasyCachingConstValue.RedisBusSection) { var dbConfig = configuration.GetSection(sectionName); var redisOptions = new RedisBusOptions(); diff --git a/src/EasyCaching.Core/Internal/EasyCachingConstValue.cs b/src/EasyCaching.Core/Internal/EasyCachingConstValue.cs index 55ffb426..9d94e559 100644 --- a/src/EasyCaching.Core/Internal/EasyCachingConstValue.cs +++ b/src/EasyCaching.Core/Internal/EasyCachingConstValue.cs @@ -35,6 +35,16 @@ public class EasyCachingConstValue /// public const string InMemorySection = "easycaching:inmemory"; + /// + /// The redis bus section. + /// + public const string RedisBusSection = "easycaching:redisbus"; + + /// + /// The rabbitMQ Bus section. + /// + public const string RabbitMQBusSection = "easycaching:rabbitmqbus"; + /// /// The default name of the in-memory. /// From 5b4d482fe71711eecc2cbefc6db90de51eeeb406 Mon Sep 17 00:00:00 2001 From: catcherwong Date: Mon, 11 Feb 2019 15:51:40 +0800 Subject: [PATCH 2/8] :speech_balloon: Update nuget icon url --- src/EasyCaching.Bus.RabbitMQ/EasyCaching.Bus.RabbitMQ.csproj | 5 +++-- src/EasyCaching.Bus.Redis/EasyCaching.Bus.Redis.csproj | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/EasyCaching.Bus.RabbitMQ/EasyCaching.Bus.RabbitMQ.csproj b/src/EasyCaching.Bus.RabbitMQ/EasyCaching.Bus.RabbitMQ.csproj index 0871cb3b..bbf67258 100644 --- a/src/EasyCaching.Bus.RabbitMQ/EasyCaching.Bus.RabbitMQ.csproj +++ b/src/EasyCaching.Bus.RabbitMQ/EasyCaching.Bus.RabbitMQ.csproj @@ -1,5 +1,6 @@ - + + netstandard2.0 Catcher Wong @@ -13,7 +14,7 @@ https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE https://github.com/dotnetcore/EasyCaching https://github.com/dotnetcore/EasyCaching - https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/easycaching-icon.png + https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png $(EasyCachingRabbitBusPackageNotes) diff --git a/src/EasyCaching.Bus.Redis/EasyCaching.Bus.Redis.csproj b/src/EasyCaching.Bus.Redis/EasyCaching.Bus.Redis.csproj index 5ef428bf..1d1dab6c 100644 --- a/src/EasyCaching.Bus.Redis/EasyCaching.Bus.Redis.csproj +++ b/src/EasyCaching.Bus.Redis/EasyCaching.Bus.Redis.csproj @@ -1,5 +1,6 @@ - + + netstandard2.0 Catcher Wong @@ -13,7 +14,7 @@ https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE https://github.com/dotnetcore/EasyCaching https://github.com/dotnetcore/EasyCaching - https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/easycaching-icon.png + https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png $(EasyCachingRedisBusPackageNotes) From 51dfc9cb67492693cdeffe22bb8b71535b400b98 Mon Sep 17 00:00:00 2001 From: catcherwong Date: Mon, 11 Feb 2019 15:59:26 +0800 Subject: [PATCH 3/8] :sparkles: Add RemoveByPrefix/RemoveByPrefixAsync. --- build/releasenotes.props | 12 ++--- build/version.props | 8 ++-- .../EasyCaching.Demo.Providers.csproj | 1 + .../Bus/EasyCachingMessage.cs | 6 +++ .../IHybridCachingProvider.cs | 11 +++++ .../HybridCachingProvider.cs | 48 +++++++++++++++++++ 6 files changed, 76 insertions(+), 10 deletions(-) diff --git a/build/releasenotes.props b/build/releasenotes.props index c795beb3..00931dd9 100644 --- a/build/releasenotes.props +++ b/build/releasenotes.props @@ -1,8 +1,8 @@ - - 1. EasyCaching Bus - 2. HybridCaching + + 1. HybridCaching add RemoveByPrefix/RemoveByPrefixAsync + 2. Add Bus Section Const value. 1. Adjust reference namespace. @@ -17,7 +17,7 @@ 1. Adjust reference namespace. - 1. Refactor. + 1. HybridCaching add RemoveByPrefix/RemoveByPrefixAsync 1. Adjust reference namespace. @@ -41,10 +41,10 @@ 1. Adjust reference namespace. - 1. Init. + 1. Modify the default section name. - 1. Init. + 1. Modify the default section name. diff --git a/build/version.props b/build/version.props index 83d48727..d22ae646 100644 --- a/build/version.props +++ b/build/version.props @@ -1,11 +1,11 @@ - 0.5.0 + 0.5.0.1 0.5.0 0.5.0 0.5.0 0.5.0 - 0.5.0 + 0.5.0.1 0.5.0 0.5.0 0.5.0 @@ -13,7 +13,7 @@ 0.5.0 0.5.0 0.5.0 - 0.5.0 - 0.5.0-alpha + 0.5.0.1 + 0.5.0-beta diff --git a/sample/EasyCaching.Demo.Providers/EasyCaching.Demo.Providers.csproj b/sample/EasyCaching.Demo.Providers/EasyCaching.Demo.Providers.csproj index dd3b067c..34371c8c 100644 --- a/sample/EasyCaching.Demo.Providers/EasyCaching.Demo.Providers.csproj +++ b/sample/EasyCaching.Demo.Providers/EasyCaching.Demo.Providers.csproj @@ -16,6 +16,7 @@ + diff --git a/src/EasyCaching.Core/Bus/EasyCachingMessage.cs b/src/EasyCaching.Core/Bus/EasyCachingMessage.cs index c8b86729..09bf6e1a 100644 --- a/src/EasyCaching.Core/Bus/EasyCachingMessage.cs +++ b/src/EasyCaching.Core/Bus/EasyCachingMessage.cs @@ -19,5 +19,11 @@ public class EasyCachingMessage /// /// The cache keys. public string[] CacheKeys { get; set; } + + /// + /// Gets or sets a value indicating whether this is prefix. + /// + /// true if is prefix; otherwise, false. + public bool IsPrefix { get; set; } } } diff --git a/src/EasyCaching.Core/IHybridCachingProvider.cs b/src/EasyCaching.Core/IHybridCachingProvider.cs index 71ffc239..a82e4abd 100644 --- a/src/EasyCaching.Core/IHybridCachingProvider.cs +++ b/src/EasyCaching.Core/IHybridCachingProvider.cs @@ -141,5 +141,16 @@ public interface IHybridCachingProvider /// The 1st type parameter. Task> GetAsync(string cacheKey, Func> dataRetriever, TimeSpan expiration); + /// + /// Removes cached item by cachekey's prefix. + /// + /// Prefix of CacheKey. + void RemoveByPrefix(string prefix); + + /// + /// Removes cached item by cachekey's prefix async. + /// + /// Prefix of CacheKey. + Task RemoveByPrefixAsync(string prefix); } } diff --git a/src/EasyCaching.HybridCache/HybridCachingProvider.cs b/src/EasyCaching.HybridCache/HybridCachingProvider.cs index 62ea2b7e..ce8f78f8 100644 --- a/src/EasyCaching.HybridCache/HybridCachingProvider.cs +++ b/src/EasyCaching.HybridCache/HybridCachingProvider.cs @@ -88,6 +88,21 @@ private void OnMessage(EasyCachingMessage message) // each clients will recive the message, current client should ignore. if (!string.IsNullOrWhiteSpace(message.Id) && message.Id.Equals(_cacheId, StringComparison.OrdinalIgnoreCase)) return; + + //remove by prefix + if(message.IsPrefix) + { + var prefix = message.CacheKeys.First(); + + _localCache.RemoveByPrefix(prefix); + + if (_options.EnableLogging) + { + _logger.LogTrace($"remove local cache that prefix is {prefix}"); + } + + return; + } foreach (var item in message.CacheKeys) { @@ -429,5 +444,38 @@ public async Task> GetAsync(string cacheKey, Func> data ? result : CacheValue.NoValue; } + + /// + /// Removes the by prefix. + /// + /// Prefix. + public void RemoveByPrefix(string prefix) + { + ArgumentCheck.NotNullOrWhiteSpace(prefix, nameof(prefix)); + + //distributed cache at first + _distributedCache.RemoveByPrefix(prefix); + _localCache.RemoveByPrefix(prefix); + + //send message to bus + _bus.Publish(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = new string[] { prefix } , IsPrefix = true }); + } + + /// + /// Removes the by prefix async. + /// + /// The by prefix async. + /// Prefix. + public async Task RemoveByPrefixAsync(string prefix) + { + ArgumentCheck.NotNullOrWhiteSpace(prefix, nameof(prefix)); + + await _localCache.RemoveByPrefixAsync(prefix); + + await _distributedCache.RemoveByPrefixAsync(prefix); + + //send message to bus in order to notify other clients. + await _bus.PublishAsync(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = new string[] { prefix }, IsPrefix = true }); + } } } From edc0453f80b28d594cd364e323cca40aee75e223 Mon Sep 17 00:00:00 2001 From: catcherwong Date: Tue, 12 Feb 2019 07:00:28 +0800 Subject: [PATCH 4/8] :sparkles: CSRedis Bus --- EasyCaching.sln | 7 ++ build/version.props | 31 +++---- .../Configurations/CSRedisBusOptions.cs | 23 +++++ .../Configurations/CSRedisOptionsExtension.cs | 81 ++++++++++++++++++ .../EasyCachingCSRedisClient.cs | 24 ++++++ .../EasyCachingOptionsExtensions.cs | 52 ++++++++++++ .../DefaultCSRedisBus.cs | 83 +++++++++++++++++++ .../EasyCaching.Bus.CSRedis.csproj | 33 ++++++++ 8 files changed, 319 insertions(+), 15 deletions(-) create mode 100644 src/EasyCaching.Bus.CSRedis/Configurations/CSRedisBusOptions.cs create mode 100755 src/EasyCaching.Bus.CSRedis/Configurations/CSRedisOptionsExtension.cs create mode 100755 src/EasyCaching.Bus.CSRedis/Configurations/EasyCachingCSRedisClient.cs create mode 100644 src/EasyCaching.Bus.CSRedis/Configurations/EasyCachingOptionsExtensions.cs create mode 100644 src/EasyCaching.Bus.CSRedis/DefaultCSRedisBus.cs create mode 100644 src/EasyCaching.Bus.CSRedis/EasyCaching.Bus.CSRedis.csproj diff --git a/EasyCaching.sln b/EasyCaching.sln index 415a25e5..e8f9f0fc 100644 --- a/EasyCaching.sln +++ b/EasyCaching.sln @@ -47,6 +47,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.PerformanceTest EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.CSRedis", "src\EasyCaching.CSRedis\EasyCaching.CSRedis.csproj", "{6584761E-E51C-408F-BE51-CA0F6269589B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.Bus.CSRedis", "src\EasyCaching.Bus.CSRedis\EasyCaching.Bus.CSRedis.csproj", "{861E5373-BEF6-4AA2-92C7-8F4941A079E7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -133,6 +135,10 @@ Global {6584761E-E51C-408F-BE51-CA0F6269589B}.Debug|Any CPU.Build.0 = Debug|Any CPU {6584761E-E51C-408F-BE51-CA0F6269589B}.Release|Any CPU.ActiveCfg = Release|Any CPU {6584761E-E51C-408F-BE51-CA0F6269589B}.Release|Any CPU.Build.0 = Release|Any CPU + {861E5373-BEF6-4AA2-92C7-8F4941A079E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {861E5373-BEF6-4AA2-92C7-8F4941A079E7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {861E5373-BEF6-4AA2-92C7-8F4941A079E7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {861E5373-BEF6-4AA2-92C7-8F4941A079E7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {CE61FAA2-0233-451C-991D-4222ED61C84B} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9} @@ -155,5 +161,6 @@ Global {2A8D7103-DF64-47B6-A406-8F8559AF7E7F} = {EBB55F65-7D07-4281-8D5E-7B0CA88E1AD0} {6EBE36A2-F128-4C63-B90A-B700D8C2F2E8} = {EBB55F65-7D07-4281-8D5E-7B0CA88E1AD0} {6584761E-E51C-408F-BE51-CA0F6269589B} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9} + {861E5373-BEF6-4AA2-92C7-8F4941A079E7} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9} EndGlobalSection EndGlobal diff --git a/build/version.props b/build/version.props index d22ae646..1261abb7 100644 --- a/build/version.props +++ b/build/version.props @@ -1,19 +1,20 @@ - 0.5.0.1 - 0.5.0 - 0.5.0 - 0.5.0 - 0.5.0 - 0.5.0.1 - 0.5.0 - 0.5.0 - 0.5.0 - 0.5.0 - 0.5.0 - 0.5.0 - 0.5.0 - 0.5.0.1 - 0.5.0-beta + 0.5.1-alpha + 0.5.1-alpha + 0.5.1-alpha + 0.5.1-alpha + 0.5.1-alpha + 0.5.1-alpha + 0.5.1-alpha + 0.5.1-alpha + 0.5.1-alpha + 0.5.1-alpha + 0.5.1-alpha + 0.5.1-alpha + 0.5.1-alpha + 0.5.1-alpha + 0.5.1-alpha + 0.5.1-alpha diff --git a/src/EasyCaching.Bus.CSRedis/Configurations/CSRedisBusOptions.cs b/src/EasyCaching.Bus.CSRedis/Configurations/CSRedisBusOptions.cs new file mode 100644 index 00000000..bfb1c05a --- /dev/null +++ b/src/EasyCaching.Bus.CSRedis/Configurations/CSRedisBusOptions.cs @@ -0,0 +1,23 @@ +namespace EasyCaching.Bus.CSRedis +{ + using System; + using System.Collections.Generic; + + /// + /// Redis bus options. + /// + public class CSRedisBusOptions + { + /// + /// Gets or sets the node rule. + /// + /// The node rule. + public Func NodeRule { get; set; } = null; + + /// + /// Gets or sets the connection strings. + /// + /// The connection strings. + public List ConnectionStrings { get; set; } + } +} diff --git a/src/EasyCaching.Bus.CSRedis/Configurations/CSRedisOptionsExtension.cs b/src/EasyCaching.Bus.CSRedis/Configurations/CSRedisOptionsExtension.cs new file mode 100755 index 00000000..feedfd31 --- /dev/null +++ b/src/EasyCaching.Bus.CSRedis/Configurations/CSRedisOptionsExtension.cs @@ -0,0 +1,81 @@ +namespace EasyCaching.Bus.CSRedis +{ + using System; + using EasyCaching.Core.Bus; + using EasyCaching.Core.Configurations; + using EasyCaching.Core.Serialization; + using Microsoft.AspNetCore.Builder; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.DependencyInjection.Extensions; + using Microsoft.Extensions.Options; + + /// + /// Redis options extension. + /// + internal sealed class CSRedisOptionsExtension : IEasyCachingOptionsExtension + { + /// + /// The name. + /// + private const string _name = "easycachingbus"; + + /// + /// The configure. + /// + private readonly Action _configure; + + /// + /// Initializes a new instance of the class. + /// + /// Name. + /// Configure. + public CSRedisOptionsExtension(Action configure) + { + this._configure = configure; + } + + /// + /// Adds the services. + /// + /// Services. + public void AddServices(IServiceCollection services) + { + services.AddOptions(); + + services.TryAddSingleton(); + + services.Configure(_name, _configure); + + services.AddSingleton(x => + { + var optionsMon = x.GetRequiredService>(); + var options = optionsMon.Get(_name); + + var conns = options.ConnectionStrings; + var rule = options.NodeRule; + + if (conns.Count == 1) + { + var redisClient = new EasyCachingCSRedisClient(_name, conns[0]); + return redisClient; + } + else + { + var redisClient = new EasyCachingCSRedisClient(_name, rule, conns.ToArray()); + return redisClient; + } + }); + + services.AddSingleton(); + } + + /// + /// Withs the services. + /// + /// Services. + public void WithServices(IApplicationBuilder services) + { + // Method intentionally left empty. + } + } +} diff --git a/src/EasyCaching.Bus.CSRedis/Configurations/EasyCachingCSRedisClient.cs b/src/EasyCaching.Bus.CSRedis/Configurations/EasyCachingCSRedisClient.cs new file mode 100755 index 00000000..bb577f62 --- /dev/null +++ b/src/EasyCaching.Bus.CSRedis/Configurations/EasyCachingCSRedisClient.cs @@ -0,0 +1,24 @@ +namespace EasyCaching.Bus.CSRedis +{ + using System; + using global::CSRedis; + + public class EasyCachingCSRedisClient : CSRedisClient + { + private readonly string _name; + + public string Name { get { return this._name; } } + + public EasyCachingCSRedisClient(string name, string connectionString) + : base(connectionString) + { + this._name = name; + } + + public EasyCachingCSRedisClient(string name, Func NodeRule, params string[] connectionStrings) + : base(NodeRule, connectionStrings) + { + this._name = name; + } + } +} diff --git a/src/EasyCaching.Bus.CSRedis/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Bus.CSRedis/Configurations/EasyCachingOptionsExtensions.cs new file mode 100644 index 00000000..1c6253dc --- /dev/null +++ b/src/EasyCaching.Bus.CSRedis/Configurations/EasyCachingOptionsExtensions.cs @@ -0,0 +1,52 @@ +namespace EasyCaching.Bus.CSRedis +{ + using System; + using EasyCaching.Core; + using EasyCaching.Core.Configurations; + using Microsoft.Extensions.Configuration; + + /// + /// EasyCaching options extensions. + /// + public static class EasyCachingOptionsExtensions + { + /// + /// Withs the redis bus. + /// + /// The redis bus. + /// Options. + /// Configure. + public static EasyCachingOptions WithCSRedisBus(this EasyCachingOptions options, Action configure) + { + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + + options.RegisterExtension(new CSRedisOptionsExtension(configure)); + return options; + } + + /// + /// Withs the redis bus. + /// + /// The redis bus. + /// Options. + /// Configuration. + /// Section name. + public static EasyCachingOptions WithCSRedisBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = EasyCachingConstValue.RedisBusSection) + { + var dbConfig = configuration.GetSection(sectionName); + var redisOptions = new CSRedisBusOptions(); + dbConfig.Bind(redisOptions); + + void configure(CSRedisBusOptions x) + { + x.ConnectionStrings = redisOptions.ConnectionStrings; + } + + options.RegisterExtension(new CSRedisOptionsExtension(configure)); + return options; + } + } +} diff --git a/src/EasyCaching.Bus.CSRedis/DefaultCSRedisBus.cs b/src/EasyCaching.Bus.CSRedis/DefaultCSRedisBus.cs new file mode 100644 index 00000000..8c7199ec --- /dev/null +++ b/src/EasyCaching.Bus.CSRedis/DefaultCSRedisBus.cs @@ -0,0 +1,83 @@ +namespace EasyCaching.Bus.CSRedis +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading; + using System.Threading.Tasks; + using EasyCaching.Core.Bus; + using Newtonsoft.Json; + + public class DefaultCSRedisBus : IEasyCachingBus + { + /// + /// The cache. + /// + private readonly EasyCachingCSRedisClient _client; + + /// + /// The handler. + /// + private Action _handler; + + /// + /// Initializes a new instance of the class. + /// + /// Clients. + public DefaultCSRedisBus(IEnumerable clients) + { + this._client = clients.FirstOrDefault(x => x.Name.Equals("easycachingbus")); + } + + /// + /// Publish the specified topic and message. + /// + /// Topic. + /// Message. + public void Publish(string topic, EasyCachingMessage message) + { + var msg = JsonConvert.SerializeObject(message); + + _client.Publish(topic, msg); + } + + /// + /// Publishs the async. + /// + /// The async. + /// Topic. + /// Message. + /// Cancellation token. + public async Task PublishAsync(string topic, EasyCachingMessage message, CancellationToken cancellationToken = default(CancellationToken)) + { + var msg = JsonConvert.SerializeObject(message); + + await _client.PublishAsync(topic, msg); + } + + /// + /// Subscribe the specified topic and action. + /// + /// Topic. + /// Action. + public void Subscribe(string topic, Action action) + { + _handler = action; + + _client.Subscribe( + (topic, msg => OnMessage(msg.Body)) + ); + } + + /// + /// Ons the message. + /// + /// Body. + private void OnMessage(string body) + { + var message = JsonConvert.DeserializeObject(body); + + _handler?.Invoke(message); + } + } +} diff --git a/src/EasyCaching.Bus.CSRedis/EasyCaching.Bus.CSRedis.csproj b/src/EasyCaching.Bus.CSRedis/EasyCaching.Bus.CSRedis.csproj new file mode 100644 index 00000000..565c7adc --- /dev/null +++ b/src/EasyCaching.Bus.CSRedis/EasyCaching.Bus.CSRedis.csproj @@ -0,0 +1,33 @@ + + + + + netstandard2.0 + Catcher Wong + Catcher Wong + $(EasyCachingRedisBusPackageVersion) + + A simple caching bus(message bus) based on CSRedis. + + Bus,Hybrid,Redis,Caching,Cache + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE + https://github.com/dotnetcore/EasyCaching + https://github.com/dotnetcore/EasyCaching + https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png + + $(EasyCachingRedisBusPackageNotes) + + + + + + + + + + + + + + From 7eb44796b4b54fd3fcd8976ec3e3753fbf8c82ef Mon Sep 17 00:00:00 2001 From: catcherwong Date: Tue, 12 Feb 2019 22:32:59 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=93=84=20Update=20License(.NET=20Core?= =?UTF-8?q?=20Community=20and=20Contributors)=20[ci=20skip]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 0608e35d..9b54c526 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2018 CatcherWong +Copyright (c) .NET Core Community and Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 62a2c93201b7b4683b32310ac73155a1fca7f5a7 Mon Sep 17 00:00:00 2001 From: catcherwong Date: Wed, 13 Feb 2019 22:34:41 +0800 Subject: [PATCH 6/8] :ok_hand: Update the default name of SQLite Provider. --- src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs b/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs index 45ffc180..87be581a 100644 --- a/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs +++ b/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs @@ -60,7 +60,7 @@ public DefaultSQLiteCachingProvider( this._logger = loggerFactory?.CreateLogger(); this._cache = _dbProvider.GetConnection(); this._cacheStats = new CacheStats(); - this._name = EasyCachingConstValue.DefaultRedisName; + this._name = EasyCachingConstValue.DefaultSQLiteName; } public DefaultSQLiteCachingProvider( From eb83eefe72a56bcdb4fec5547cbe4c0c37ae0bbc Mon Sep 17 00:00:00 2001 From: catcherwong Date: Thu, 14 Feb 2019 20:50:56 +0800 Subject: [PATCH 7/8] :bookmark: Release v0.5.1 --- build/releasenotes.props | 27 +++++++++++++++------------ build/version.props | 32 ++++++++++++++++---------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/build/releasenotes.props b/build/releasenotes.props index 00931dd9..6a56cdcc 100644 --- a/build/releasenotes.props +++ b/build/releasenotes.props @@ -5,46 +5,49 @@ 2. Add Bus Section Const value. - 1. Adjust reference namespace. + 1. Update EasyCaching.Core. - 1. Adjust reference namespace. + 1. Update EasyCaching.Core. - 1. Adjust reference namespace. + 1. Update EasyCaching.Core. + 2. Update Default name of provider. - 1. Adjust reference namespace. + 1. Update EasyCaching.Core. - 1. HybridCaching add RemoveByPrefix/RemoveByPrefixAsync + 1. HybridCaching add RemoveByPrefix/RemoveByPrefixAsync - 1. Adjust reference namespace. + 1. Update EasyCaching.Core. - 1. Adjust reference namespace. + 1. Update EasyCaching.Core. - 1. Adjust reference namespace. + 1. Update EasyCaching.Core. - 1. Adjust reference namespace. + 1. Update EasyCaching.Core. - 1. Adjust reference namespace. + 1. Update EasyCaching.Core. - 1. Adjust reference namespace. + 1. Update EasyCaching.Core. - 1. Adjust reference namespace. + 1. Update EasyCaching.Core. 1. Modify the default section name. + 2. Update EasyCaching.Core. 1. Modify the default section name. + 2. Update EasyCaching.Core. diff --git a/build/version.props b/build/version.props index 1261abb7..8247f6e0 100644 --- a/build/version.props +++ b/build/version.props @@ -1,20 +1,20 @@ - 0.5.1-alpha - 0.5.1-alpha - 0.5.1-alpha - 0.5.1-alpha - 0.5.1-alpha - 0.5.1-alpha - 0.5.1-alpha - 0.5.1-alpha - 0.5.1-alpha - 0.5.1-alpha - 0.5.1-alpha - 0.5.1-alpha - 0.5.1-alpha - 0.5.1-alpha - 0.5.1-alpha - 0.5.1-alpha + 0.5.1 + 0.5.1 + 0.5.1 + 0.5.1 + 0.5.1 + 0.5.1 + 0.5.1 + 0.5.1 + 0.5.1 + 0.5.1 + 0.5.1 + 0.5.1 + 0.5.1 + 0.5.1 + 0.5.1 + 0.5.1 From f03a0b12ce5ad1f772fc4d89ba5544ee516e5cd3 Mon Sep 17 00:00:00 2001 From: catcherwong Date: Sat, 16 Feb 2019 20:53:00 +0800 Subject: [PATCH 8/8] :bug: Fixed some bugs of RabbitMQBus. --- build/releasenotes.props | 4 ++-- build/version.props | 2 +- .../EasyCachingOptionsExtensions.cs | 2 +- .../Configurations/RabbitMQBusOptions.cs | 2 +- .../DefaultRabbitMQBus.cs | 15 ++++++++------- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/build/releasenotes.props b/build/releasenotes.props index 6a56cdcc..d8453fea 100644 --- a/build/releasenotes.props +++ b/build/releasenotes.props @@ -46,8 +46,8 @@ 2. Update EasyCaching.Core. - 1. Modify the default section name. - 2. Update EasyCaching.Core. + 1. Fixed Options Bug. + 2. Fixed Queue Bind Bug. diff --git a/build/version.props b/build/version.props index 8247f6e0..18115f2f 100644 --- a/build/version.props +++ b/build/version.props @@ -15,6 +15,6 @@ 0.5.1 0.5.1 0.5.1 - 0.5.1 + 0.5.1.1 diff --git a/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs index 76ae31ee..c44768da 100644 --- a/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs @@ -47,7 +47,7 @@ void configure(RabbitMQBusOptions x) x.Port = busOptions.Port; x.QueueMessageExpires = busOptions.QueueMessageExpires; x.RequestedConnectionTimeout = busOptions.RequestedConnectionTimeout; - x.RouteKey = busOptions.RouteKey; + //x.RouteKey = busOptions.RouteKey; x.SocketReadTimeout = busOptions.SocketReadTimeout; x.SocketWriteTimeout = busOptions.SocketWriteTimeout; x.TopicExchangeName = busOptions.TopicExchangeName; diff --git a/src/EasyCaching.Bus.RabbitMQ/Configurations/RabbitMQBusOptions.cs b/src/EasyCaching.Bus.RabbitMQ/Configurations/RabbitMQBusOptions.cs index bf0da3d2..5b2bb79b 100644 --- a/src/EasyCaching.Bus.RabbitMQ/Configurations/RabbitMQBusOptions.cs +++ b/src/EasyCaching.Bus.RabbitMQ/Configurations/RabbitMQBusOptions.cs @@ -11,7 +11,7 @@ public class RabbitMQBusOptions : BaseRabbitMQOptions /// Gets or sets the route key. /// /// The route key. - public string RouteKey { get; set; } = "rmq.queue.undurable.easycaching.subscriber.*"; + //public string RouteKey { get; set; } = "rmq.queue.undurable.easycaching.subscriber.*"; /// /// Gets or sets the name of the queue. diff --git a/src/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs b/src/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs index a8c178ae..dd517018 100644 --- a/src/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs +++ b/src/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs @@ -8,6 +8,7 @@ using global::RabbitMQ.Client; using global::RabbitMQ.Client.Events; using Microsoft.Extensions.ObjectPool; + using Microsoft.Extensions.Options; /// /// Default RabbitMQ Bus. @@ -52,10 +53,10 @@ public class DefaultRabbitMQBus : IEasyCachingBus /// Serializer. public DefaultRabbitMQBus( IPooledObjectPolicy _objectPolicy - ,RabbitMQBusOptions rabbitMQOptions - ,IEasyCachingSerializer serializer) + , IOptions rabbitMQOptions + , IEasyCachingSerializer serializer) { - this._options = rabbitMQOptions; + this._options = rabbitMQOptions.Value; this._serializer = serializer; var factory = new ConnectionFactory @@ -132,7 +133,7 @@ public void Publish(string topic, EasyCachingMessage message) } return Task.CompletedTask; } - + /// /// Subscribe the specified topic and action. /// @@ -142,7 +143,7 @@ public void Subscribe(string topic, Action action) { _handler = action; var queueName = string.Empty; - if(string.IsNullOrWhiteSpace(_options.QueueName)) + if (string.IsNullOrWhiteSpace(_options.QueueName)) { queueName = $"rmq.queue.undurable.easycaching.subscriber.{_busId}"; } @@ -151,13 +152,13 @@ public void Subscribe(string topic, Action action) queueName = _options.QueueName; } - Task.Factory.StartNew(() => + Task.Factory.StartNew(() => { var model = _subConnection.CreateModel(); model.ExchangeDeclare(_options.TopicExchangeName, ExchangeType.Topic, true, false, null); model.QueueDeclare(queueName, false, false, true, null); // bind the queue with the exchange. - model.QueueBind(_options.TopicExchangeName, queueName, _options.RouteKey); + model.QueueBind(queueName, _options.TopicExchangeName, topic); var consumer = new EventingBasicConsumer(model); consumer.Received += OnMessage; consumer.Shutdown += OnConsumerShutdown;