Hangfire 官方支持 MSSQL 与 Redis(Hangfire.Pro.Redis) 两种 ,由于我的数据库是 MYSQL ,粗略查询了一下文档,现在对 .NET Core 支持的并不够好,所有就选择了 Redis;当然也可以使用第三方来支持 PostgreSql,Mongo

安装 Redis

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:chris-lea/redis-server
sudo apt-get update
sudo apt-get install redis-server
ps aux | grep redis
sudo service redis-server restart
sudo apt-get remove redis-server
redis-cli
#注释bind
# bind 127.0.0.1
#守护进程启动
daemonize yes
#保护模式[无密码模式设置为no]
protected-mode no
#设置密码
requirepass test
Mac 下安装 Redis Desktop Manager(官方 Mac 版只支持源码重编译)

#install brew cask
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null ; brew install caskroom/cask/brew-cask 2> /dev/null
#install Redis Desktop Manager
brew cask install rdm

Asp.Net Core 集成Hangfire

Hangfire.Pro 是对 Hangfire 的一个扩展,使用自己搭建的 Nuget 源,Hangfire.Pro.Redis 是其中的一个扩展 ;我这里是使用的 Hangfire.Redis.StackExchange 基本满足需求。

增加 package
<PackageReference Include="Hangfire.AspNetCore" Version="1.6.12" />
<PackageReference Include="Hangfire.Redis.StackExchange.StrongName" Version="1.7.0" />
<PackageReference Include="StackExchange.Redis.StrongName" Version="1.2.3" />
配置 Hangfire 服务

 /// <summary>
/// 启动类
/// </summary>
public class Startup
{
/// <summary>
/// 配置接口
/// </summary>
public IConfigurationRoot Configuration { get; } /// <summary>
/// Redis 服务
/// </summary>
public static ConnectionMultiplexer Redis; /// <summary>
/// 构造方法
/// </summary>
/// <param name="env"></param>
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
Redis = ConnectionMultiplexer.Connect(Configuration.GetConnectionString("Redis"));
} // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
//自定义的配置
services.Configure<DbSetting>(Configuration.GetSection("ConnectionStrings"));
//返回大小写问题
services.AddMvc()
.AddJsonOptions(option => option.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver());
//注入Hangfire服务
services.AddHangfire(config => config.UseRedisStorage(Redis));
} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug(); if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
} app.UseStaticFiles(); app.UseHangfireServer();
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
Authorization = new[] { new HangfireDashboardAuthorizationFilter() }
}); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Hq}/{action=Index}/{id?}");
});
}
}
https://github.com/marcoCasamento/Hangfire.Redis.StackExchange
http://docs.hangfire.io/en/latest/configuration/using-redis.html
https://github.com/uglide/RedisDesktopManager
https://www.hangfire.io/extensions.html

最新文章

  1. Git命令
  2. css3 -- 属性选择器
  3. Upgrading to Java 8——第一章 Lambda表达式
  4. 【C语言】-循环结构-for语句
  5. 关于SharePoint 2010体系架构的几个话题
  6. 修改MySQL默认最大连接数
  7. Iframe知识点
  8. Xcode7修改模块生成网络权限(ATS配置)
  9. LB 高可扩展性集群(负载均衡集群)
  10. Android Scheme协议与应用全解析
  11. 新概念英语(1-23)Which glasses?
  12. python 虚拟环境的搭建
  13. AJAX完整操作
  14. winform创建快捷方式
  15. (已解决)Xcode 换电脑提示 Could not attach to pid:“XXXX”错误
  16. c++实现循环队列
  17. 制作U盘启动盘并重装系统
  18. 初始化android studio的方法
  19. PAT甲1031 Hello World for U【字符串】
  20. Xcode10.x适配的部分问题

热门文章

  1. 学以致用十六-----Centos7.2编译安装mysql5.6.22
  2. 学以致用二---配置Centos7.2 基本环境
  3. 从客户端(f=&quot;&lt;zhaoyuntang.com&quot;)中检测到有潜在危险的 Request.Form 值。
  4. java使用filter设置跨域访问
  5. python中global 和 nonlocal的使用
  6. js 上传文件夹
  7. 修改input标签type=file类型的文字
  8. 第80讲:List的泛型分析以及::类和Nil对象
  9. &lt;c:forEach varStatus=&quot;status&quot;&gt;中 varStatus的属性简介
  10. Android自适应屏幕的实现方法