Skip to main content

Notification Background Processing

Summary

NotificationEventConsumer is the only hosted BackgroundService. It connects to the RabbitMQ topic exchange, declares and binds its queue to the supported event routing keys, and hands each delivery to a freshly-scoped NotificationDispatcher, acknowledging on success and requeuing on unexpected failure.

Consumer lifecycle

Connection and resilience

The consumer builds a ConnectionFactory from the bound RabbitMq options with automatic recovery enabled and a network recovery interval. Connection failures are caught, logged as a warning and retried every five seconds, so a temporarily-unavailable broker never crashes startup.

Topology

It declares the integration-events topic exchange (durable), declares its own durable queue, and binds one routing key per entry in EventNotificationResolver.SupportedEventTypes. BasicQos applies the configured prefetch count. Consumption uses manual acknowledgement.

Per-message handling

Each delivery is parsed into a NotificationEventEnvelope from AMQP properties and headers (event id, type, correlation, tenant, source, occurred-at, schema version, payload and an x-force-fail flag). Handling occurs in its own DI scope. On success the message is acked; an unhandled error nacks with requeue so the broker redelivers.

Envelope

NotificationEventEnvelope is an immutable record; EffectiveCorrelationId falls back to the event id when the producer sent no correlation id.

Test hooks

Two API endpoints exercise this path without a live broker producer: /notifications/test/dispatch runs an event straight through the dispatcher, and /notifications/test/publish publishes onto the bus so the consumer round-trips it.

Verified absence

There is no additional worker, scheduler, timer-based HostedService or outbox relay in the service. The consumer is the single background component.

Requires Confirmation

Production broker cluster, virtual host, prefetch tuning and dead-letter enablement require confirmation.

Source References

  • microservices/src/notification-service/Messaging/NotificationEventConsumer.cs
  • microservices/src/notification-service/Messaging/NotificationEventEnvelope.cs
  • microservices/src/notification-service/Program.cs

See Also

Keywords

Background service, event consumer, RabbitMQ, ack, requeue, prefetch.

Revision Information

  • Status: Draft
  • Last reviewed: 2026-07-21
  • Next review: 2026-10-21