HookSentry: Guida ai Webhook Resilienti
#python#automation#microsaas
Smetti di perdere i webhook critici di Stripe e Shopify. Questa guida autorevole di ingegneria rivela come costruire un proxy Go self-hosted e resiliente con verifica HMAC, buffering WAL, retry automatici e alert DLQ. Sostituisci i costosi strumenti SaaS per webhook da 150 $/mese con la CLI chiavi in mano di HookSentry.
Leggi l'approfondimento tecnicoArchitettura Webhook a Tolleranza Zero: Da SaaS Esterni a Proxy Self-Hostedmain.pymain.py — estratto d'esempio nello stile del tool
#!/usr/bin/env python3
"""
HookSentry - Resilient Webhook Proxy & Relay Manager
A robust CLI engine for managing local and production webhook streams.
HookSentry intercepts, verifies, and buffers incoming Stripe and Shopify
webhooks using Write-Ahead Logging (WAL) and automatic Dead-Letter Queue
(DLQ) retry orchestration to ensure zero payload loss.
Features:
- HMAC signature verification for Stripe, Shopify, and custom providers
- Durable Write-Ahead Log (WAL) buffering for instant ingestion
- Exponential backoff retries with jitter and configurable thresholds
- Dead-Letter Queue (DLQ) isolation and automated alert triggers
Usage:
$ python main.py start --config hooksentry.json
$ python main.py replay --dlq-id dlq_8f92a1b
"""
from __future__ import annotations
import enum
import hmac
import logging
import time
from dataclasses import dataclass, field
from typing import Any, Dict, Optional
logger = logging.getLogger("hooksentry")
class WebhookState(str, enum.Enum):
"""Lifecycle states for ingested webhook events."""
RECEIVED = "received"
VERIFIED = "verified"
DELIVERED = "delivered"
RETRYING = "retrying"
DEAD_LETTER = "dead_letter"
@dataclass(frozen=True)
class WebhookEvent:
"""Domain model representing an incoming webhook payload."""
event_id: str
provider: str
payload: Dict[str, Any]
headers: Dict[str, str]
timestamp: float = field(default_factory=time.time)
state: WebhookState = WebhookState.RECEIVED
class HookSentryEngine:
"""Core engine orchestrating HMAC validation, WAL ingestion, and retries."""
# ... the full file ships with your download