该项目提供了一组.NET工具,用于管理事件,基本转换和此类事件事件的通知( Webhooks ):在全球设计范围内,该模型启用了事件驱动的架构,并在其他系统发生预期的发生时触发系统过程。
尽管此集成模型被主要服务提供商(例如SendGrid , Twilio , Github , Slack等)广泛采用,但没有正式的协议或权限可以执行合规性(例如对于其他情况,例如OpenID,OpenAPI等)。
无论如何,典型的实现包括以下元素:
我试图在此资料库中的此页面中更详细地表达这些概念(没有任何教学的野心)。
框架当前提供的库如下:
| 图书馆 | nuget | github(预发行) |
|---|---|---|
| deveel.webhooks | ||
| deveel.webhooks.sender | ||
| deveel.webhooks.service | ||
| deveel.webhooks.mongodb | ||
| deveel.webhooks.entityframework | ||
| deveel.webhooks.dynamiclinq | ||
| deveel.webhooks.receiver.aspnetcore |
以下库将框架扩展到特定提供者的接收器:
| 图书馆 | nuget | github(预发行) |
|---|---|---|
| deveel.webhooks.receiver.twilio | ||
| deveel.webhooks.receiver.sendgrid | ||
| deveel.webhooks.receiver.facebook |
您可以从Nuget官方频道获得这些库的稳定版本。
要获取可以从Deveel软件包管理器还原的包装的最新释放版本。
我们想帮助您开始此框架并最终将其扩展:请参考文档部分或我们为您制作的官方网站。
最简单的入门方法是遵循“入门指南”,但您还可以参考常见问题部分,以获取最常见问题的答案。
在从事.NET Core 3.1/.NET 5 PAA (平台-As-Service )项目的同时,该项目需要功能,该服务的用户能够能够通过HTTP渠道创建系统到系统到系统的订阅和事件的通知(通常是命名的Webhooks ,或HTTP PARKENT ),以避免我的设计,但我避免了我的设计,以避免我的设计,以避免使用该练习。在这种野心中感到沮丧:
该框架的文档将为您提供有关框架的要求,配置,使用和可扩展性的更多详细信息。
无论如何,为了帮助您开始框架,请考虑以下示例,这些示例显示了如何创建简单的Webhook管理服务,处理订阅和通知以及客户端接收器。
作为服务提供商,该库提供了处理Webhook模式的两个主要方面的功能:
以下示例显示了如何创建Webhook订阅,以及如何将通知发送到订户端点:
using Microsoft . AspNetCore . Builder ;
using Deveel . Webhooks ;
namespace Example {
public class Program {
public static void Main ( string [ ] args ) {
var builder = WebApplication . CreateBuilder ( args ) ;
// ...
builder . Services . AddWebhookSubscriptions < MongoWebhookSubscription > ( subs => {
subs . UseMongoDb ( "mongodb://localhost:27017" )
. UseSubscriptionResolver ( ) ;
} ) ;
builder . Services . AddWebhookNotifier < MyWebhook > ( notifier => {
notifier . UseSender ( sender => {
sender . Configure ( options => {
options . Timeout = TimeSpan . FromSeconds ( 30 ) ;
} ) ;
} ) ;
} ) ;
var app = builder . Build ( ) ;
// ...
// ... and notify the receivers manually ...
app . MapPost ( "/webhooks" , async ( HttpContext context ,
[ FromServices ] IWebhookSender < MyWebhook > sender , [ FromBody ] MyWebhookModel webhook ) => {
var destination = webhook . Destination . ToWebhookDestination ( ) ;
var result = await sender . SendAsync ( destination , webhook , context . HttpContext . RequestAborted ) ;
// ...
return Results . Ok ( ) ;
} ) ;
// ... or notify the webhooks automatically from subscriptions
app . MapPost ( "/webhooks/notify" , async ( HttpContext context ,
[ FromServices ] IWebhookNotifier < MyWebhook > notifier , [ FromBody ] MyEventModel eventModel ) => {
var eventInfo = eventModel . AsEventInfo ( ) ;
var result = await notifier . NotifyAsync ( eventInfo , context . HttpContext . RequestAborted ) ;
// you can log the result of the notification to all receivers ...
return Results . Ok ( ) ;
} ) ;
app . Run ( ) ;
}
}
} 该框架还提供了一组内置的接收器,可用于从应用程序中的订阅端点处理传入通知。
以下示例显示了如何为由Facebook Messenger消息支持的Webhook创建接收器:
namespace Example {
public class Program {
public static void Main ( string [ ] args ) {
var builder = WebApplication . CreateBuilder ( args ) ;
// ...
builder . Services . AddFacebookReceiver ( )
. AddHandler < MyFacebookWebhookHandler > ( ) ;
var app = builder . Build ( ) ;
// ...
// ... you can handle all the incoming webhooks at "/webhooks/facebook"
// invoking all the handlers registered in the service collection ...
app . MapFacebookWebhook ( "/webhooks/facebook" ) ;
// ... or you can handle the incoming webhooks manually ...
app . MapFacebookWebhook ( "/webhooks/facebook2" , async ( FacebookWebhook webhook , IService service , CancellationToken ct ) => {
// ...
await service . DoSomethingAsync ( webhook , ct ) ;
} ) ;
app . Run ( ) ;
}
}
} 如果他们尊重我们对其功能的某些期望,那么对使用Deveel Webhooks等开源项目的贡献通常受到使用产品和服务的兴趣。
贡献和提高该项目质量的最佳方法是尝试,提交问题,加入设计对话以及进行拉装。
请参考贡献指南,以获取有关如何为该项目贡献的更多详细信息。
我们旨在通过提供文档,回答常见问题并跟进错误报告和功能请求等问题来解决您可能遇到的大多数问题。
该项目根据Apache 2开源许可协议发布。