ABP框架系列之二十九:(Hangfire-Integration-延迟集成)
Introduction
Hangfire is a compherensive background job manager. You can integrate ASP.NET Boilerplate with Hangfire to use it instead of default background job manager. You can use the same background job API for Hangfire. Thus, your code will be independent of Hangfire. But, if you like, you can directly use Hangfire's API also.
迟发性是一个综合的后台作业管理。你可以将ASP.NET样板与迟发性来代替默认的背景作业管理器。你可以使用相同的背景工作API为迟发性。因此,您的代码将被独立的迟发。但是,如果你喜欢,你可以直接使用API迟发的。
Hangfire Integration depends on the frameworks you are using.
ASP.NET Core Integration
Abp.HangFire.AspNetCore package is used to integrate to ASP.NET Core based applications. It depends on Hangfire.AspNetCore. This document describes to install hangfire to an ASP.NET Core project. It's similar for ABP based projects too. First install Abp.HangFire.AspNetCore package to your web project:
Install-Package Abp.HangFire.AspNetCore
Then you can install any storage for Hangfire. Most common one is SQL Server storage (see Hangfire.SqlServernuget package). After you installed these nuget packages, you can configure your project to use Hangfire.
First, we are changing Startup class to add Hangfire to dependency injection and configure storage and connection string in the ConfigureServices method:
services.AddHangfire(config =>
{
config.UseSqlServerStorage(_appConfiguration.GetConnectionString("Default"));
});
Then we can add UseHangfireServer call in the Configure method:
app.UseHangfireServer();
If you want to use hangfire's dashboard, you can add it too:
如果你想用迟发的仪表盘
app.UseHangfireDashboard();
If you want to authorize the dashboard, you can use AbpHangfireAuthorizationFilter as shown below:
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
    Authorization = new[] { new AbpHangfireAuthorizationFilter("MyHangFireDashboardPermissionName") }
});
The configuration above is almost standard to integrate hangfire to an ASP.NET Core application. For ABP based projects, we should also configure our web module to replace Hangfire for ABP's default background job manager:
[DependsOn(typeof (AbpHangfireAspNetCoreModule))]
public class MyProjectWebModule : AbpModule
{
public override void PreInitialize()
{
Configuration.BackgroundJobs.UseHangfire();
} //...
}
We added AbpHangfireAspNetCoreModule as a dependency and used Configuration.BackgroundJobs.UseHangfire method to replace Hangfire for ABP's default background job manager.
Hangfire requires schema creation permission in your database since it creates it's own schema and tables on first run. See Hangfire documentation for more information.
迟发性需要在您的数据库模式创建许可,因为它创造了它自己的模式和运在第一次运行的时候。
ASP.NET MVC 5.x Integration
Abp.HangFirenuget package is used for ASP.NET MVC 5.x projects:
Install-Package Abp.HangFire
Then you can install any storage for Hangfire. Most common one is SQL Server storage (see Hangfire.SqlServernuget package). After you installed these nuget packages, you can configure your project to use Hangfire as shown below:
[DependsOn(typeof (AbpHangfireModule))]
public class MyProjectWebModule : AbpModule
{
public override void PreInitialize()
{
Configuration.BackgroundJobs.UseHangfire(configuration =>
{
configuration.GlobalConfiguration.UseSqlServerStorage("Default");
}); } //...
}
We added AbpHangfireModule as a dependency and used Configuration.BackgroundJobs.UseHangfire method to enable and configure Hangfire ("Default" is the connection string in web.config).
Hangfire requires schema creation permission in your database since it creates it's own schema and tables on first run. See Hangfire documentation for more information.
Dashboard Authorization(仪表盘授权)
Hagfire can show a dashboard page to see status of all background jobs in real time. You can configure it as described in it's documentation. By default, this dashboard page is available for all users, not authorized. You can integrate it to ABP's authorization system using AbpHangfireAuthorizationFilter class defined in Abp.HangFire package. Example configuration:
hagfire可以显示仪表板页面看到实时背景工作状态。您可以按照文档中描述的方式配置它。默认情况下,此仪表板页可供所有用户使用,未经授权。你可以将它用在Abp.HangFire包中定义的类abphangfireauthorizationfilter ABP的授权系统。配置示例:
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
    Authorization = new[] { new AbpHangfireAuthorizationFilter() }
});
This checks if current user has logged in to the application. If you want to require an additional permission, you can pass into it's constructor:
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
    Authorization = new[] { new AbpHangfireAuthorizationFilter("MyHangFireDashboardPermissionName") }
});
Note: UseHangfireDashboard should be called after authentication middleware in your Startup class (probably as the last line). Otherwise, authorization always fails.
注:usehangfiredashboard应该在你启动类认证中间件后调用(可能作为最后一行)。否则,授权总是失败。
ABP框架系列之二十九:(Hangfire-Integration-延迟集成)的更多相关文章
- ABP框架系列之二十:(Dependency-Injection-依赖注入)
		
What is Dependency Injection If you already know Dependency Injection concept, Constructor and Prope ...
 - ABP框架系列之二十四:(Email-Sending-EF-电子邮件发送)
		
Introduction Email sending is a pretty common task for almost every application. ASP.NET Boilerplate ...
 - ABP框架系列之二十六:(EventBus-Domain-Events-领域事件)
		
In C#, a class can define own events and other classes can register it to be notified when something ...
 - ABP框架系列之二十二:(Dynamic-Web-API-动态WebApi)
		
Building Dynamic Web API Controllers This document is for ASP.NET Web API. If you're interested in A ...
 - ABP框架系列之二十八:(Handling-Exceptions-异常处理)
		
Introduction This document is for ASP.NET MVC and Web API. If you're interested in ASP.NET Core, see ...
 - ABP框架系列之二十五:(Embedded-Resource-Files-嵌入式资源文件)
		
Introduction ASP.NET Boilerplate provides an easy way of using embedded Razor views (.cshtml files) ...
 - ABP源码分析二十九:ABP.MongoDb
		
这个Module通过建立一个MongoDbRepositoryBase<TEntity> 基类,封装了对MongoDb数据库的操作. 这个module通过引用MongoDB.Driver, ...
 - ABP框架系列之二十七:(Feature-Management-特征管理)
		
Introduction Most SaaS (multi-tenant) applications have editions (packages) those have different fea ...
 - ABP框架系列之二:(Entity Framework Core-实体核心框架)
		
Introduction(介绍) Abp.EntityFrameworkCore nuget package is used to integrate to Entity Framework (EF) ...
 
随机推荐
- Oracle中存储图片的类型为BLOB类型,Java中如何将其读取并转为字符串?
			
一,读取图片转为String类型: 需要使用Sun公司提供的Base64工具 String str = ((Map) list1.get(0)).get("EINVOICEFILE" ...
 - μC/Probe尝鲜
			
μC/Probe 1.添加文件 2.配置probe_com_cfg.h 2.1.选择接口 #define PROBE_COM_CFG_RS232_EN DEF_ENABLED /* Configure ...
 - Java内存泄漏的几种可能
			
Java内存泄漏引起的原因: 内存泄漏是指无用对象(不再使用的对象)持续占有内存或无用对象的内存得不到及时释放,从而造成内存空间的浪费称为内存泄漏. 长生命周期的对象持有短生命周期对象的引用就很可能发 ...
 - [UGUI]圆形Image
			
参考链接: http://www.cnblogs.com/leoin2012/p/6425089.html 前面说过Mask组件会影响性能:https://www.cnblogs.com/lyh916 ...
 - 解决idea下载依赖包慢到出奇
			
右键项目选中maven选项,然后选择“open settings.xml”或者 “create settings.xml”,然后把如下代码粘贴进去就可以了.重启IDE. <?xml versio ...
 - 阿里云视频直播PHP-SDK
			
阿里云 视频直播 配置 及 PHP-SDK 接入教程准备工作域名管理配置鉴权地址生成器及DEMO演示-熟悉鉴权接入SDK推流回调的配置阿里云 视频直播 配置 及 PHP-SDK 接入教程 个人感觉,阿 ...
 - sass的基本使用
			
使用sass的前提是安装Ruby,如果是Mac系统,那么免去安装,Windows系统需要自行安装https://www.sass.hk/install/.当安装好以后,直接执行安装sass命令:gem ...
 - Linux常用基础操作命令大全(超实用精心整理)
			
相信大家都对黑客那种只用命令行对电脑操作的风格惊呆了,其实你也可以做到.linux是一款不同于windows的操作系统,而且它是黑客.渗透人员.运维人员等等必会的.如果你想学习,小编下面整理的命令将会 ...
 - spring的ioc与aop原理
			
ioc(反向控制) 原理: 在编码阶段,既没有实例化对象,也没有设置依赖关系,而把它交给Spring,由Spring在运行阶段实例化.组装对象.这种做法颠覆了传统的写代码实例化.组装对象.然后一 ...
 - Ubuntu16下用virtualbox 安装Windows虚拟机
			
平时要用Windows系统,但是现在工作都是在Linux下面开发,所以都没装Windows,之前用vm虚拟机比较麻烦, 所以就用virtualbox搞搞: 1.sed -i '$adeb http:/ ...