在 ASP.NET Core 中运用 Hangfire:实现分布式任务处理的实战指南
最编程
2024-08-01 22:32:17
...
AspNetCore.Hangfire.Extension
hangfire extension
Add Hangfire
1 services.AddHangfire(config => 2 { 3 config.UseRedisStorage( 4 Configuration["RedisConnectionString"], 5 new RedisStorageOptions 6 { 7 Db = 7, 8 Prefix = "abc-sys" 9 }); 10 });
Use Hangfire
app.UseHangfireServer(); app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new HangfireAuthorizationFilter() }, IgnoreAntiforgeryToken = true, AppPath = "/swagger/index.html", DashboardTitle = "Abc Sys Hangfire Dashboard" }); app.AddOrUpdateJobs();
HangfireAuthorizationFilter
/// <summary> /// HangfireAuthorizationFilter /// </summary> public class HangfireAuthorizationFilter : IDashboardAuthorizationFilter { /// <summary> /// no authorize /// </summary> /// <param name="context"></param> /// <returns></returns> public bool Authorize(DashboardContext context) { return true; } }
TestJob
/// <summary> /// TestJob /// </summary> [SimpleJob(IsOpen = true, JobId = "TestJob", CronExpression = "0 0 8 * * ?")] public class TestJob : BaseRecurringJob { /// <summary> /// execute job /// </summary> /// <returns></returns> public override async Task Execute() { //todo job } }
github url:https://github.com/cailin0630/AspNetCore.Hangfire.Extension
原文地址:https://www.cnblogs.com/jiangyihz/p/12878020.html
上一篇: 如何运用编码(Coding)
推荐阅读
-
在 ASP.NET Core 中运用 Hangfire:实现分布式任务处理的实战指南
-
【2022新手指南】Java编程进阶之路 - 六、技术架构篇 ### MySQL索引底层解析与优化实战 - 你会讲解MySQL索引的数据结构吗?性能调优技巧知多少? - Redis深度揭秘:你知道多少?从基础到哨兵、主从复制全梳理 - Redis持久化及哨兵模式详解,还有集群搭建和Leader选举黑箱打开 - Zookeeper是个啥?特性和应用场景大公开 - ZooKeeper集群搭建攻略及 Leader选举、读写一致性、共享锁实现细节 - 探究ZooKeeper中的Leader选举机制及其在分布式环境中的作用 - Zab协议深入剖析:原理、功能与在Zookeeper中的核心地位 - RabbitMQ全方位解读:工作模式、消费限流、可靠投递与配置策略 - 设计者视角:RabbitMQ过期时间、死信队列与延时队列实践指南 - RocketMQ特性和应用场景揭示:理解其精髓与差异化优势 - Kafka详细介绍:特性及广泛应用于实时数据处理的场景解析 - ElasticSearch实力揭秘:特性概述与作为搜索引擎的广泛应用 - MongoDB认知升级:非关系型数据库的优势阐述,安装与使用实战教学 - BIO/NIO/AIO网络模型对比:掌握它们的区别与在网络编程中的实际应用 - Netty带你飞:理解其超快速度背后的秘密,包括线程模型分析 - 网络通信黑科技:Netty编解码原理与常用编解码器的应用,Protostuff实战演示 - 解密Netty粘包与拆包现象,怎样有效应对这一常见问题 - 自定义Netty心跳检测机制,轻松调整检测间隔时间的艺术 - Dubbo轻骑兵介绍:核心特性概览,服务降级实战与其实现益处 - Dubbo三大神器解读:本地存根与本地伪装的实战运用与优势呈现 ----------------------- 七、结语与回顾