Skip to main content

Events and messages (RabbitMQ)

The service talks to the rest of PVC Connect asynchronously through RabbitMQ, using MassTransit 8. Payloads are the records in Integrations.Contracts (Events for what we publish, Messages for what we consume), serialized as camelCase JSON with enums as strings, the same shapes as the REST DTOs. Exchanges are named pvc.integrations.<message-name> (e.g. pvc.integrations.tax-document-committed), pinned so they don't change when C# namespaces do; TopologyTests snapshots every exchange and queue.

Published​

EventRaised when
TaxDocumentSavedTax calculated and recorded, not committed
TaxDocumentCommittedA document became reportable (drives the GL)
TaxCalculationDeferredAvaTax unavailable; document is PendingTax
TaxCalculationFailedAvaTax rejected the document
TaxDocumentVoidedA document was voided
ExchangeRateLockedFirst lock of the day for a pair
DailyExchangeRatesImportedNew daily rates stored
PartySyncFailedAvalara rejected a customer or vendor
ResaleCertificateRequestedA resale certificate is needed for a vendor/PO
CertificateRequestFulfilledThe certificate is now on file
ExemptionCertificateExpiringA customer certificate is expiring or expired
TaxReconciliationCompletedNightly reconciliation finished

Consumed​

MessageEffect
WorkOrderInvoiceFinalizedCreate (and commit) the AR document
VendorBillApprovedCreate the AP (use tax) document
PurchaseOrderCommittedRecord a resale certificate request when one is required
CreditMemoIssuedCredit an earlier document
TaxDocumentVoidRequestedVoid an earlier document
CustomerUpsertedStore and sync a customer to each sharing entity
VendorUpsertedStore and sync a vendor to each sharing entity

Conventions​

  • Naming: events are past tense facts (TaxDocumentCommitted). Consumed messages are facts from the sender's side (VendorBillApproved), never commands to this service, except the explicit ...Requested messages.
  • Delivery: at least once. Published through the transactional outbox, and consumed through the inbox (de-duplicated). Handlers are idempotent on the caller's ids.
  • Queues: one per consumer, kebab-case (e.g. credit-memo-issued). Use one RabbitMQ virtual host per environment: exchanges are shared by every queue in a virtual host.
  • Retries: invalid messages and business rejections go straight to <queue>_error, with a Fault<T> for the sender. Messages that can't be handled yet (the original invoice hasn't arrived or isn't committed, a concurrent update, AvaTax is down) are parked in Postgres and redelivered after 1 m, 5 m, 15 m, 1 h and 4 h, then go to _error. Unexpected transient failures are retried 5 times right away. See ADR 0008.
  • Ordering: none is assumed. Retry-later handles messages that cross (a credit before its invoice), and CustomerUpserted/VendorUpserted carry an optional version so an older change never overwrites a newer one.
  • Who may publish: each publishing service should use its own broker user and set the AMQP user_id property. Once Messaging__Publishers lists them, a message acts only on its publisher's entities, and anything else goes to _error. Events this service publishes carry its own user_id. See Security.
  • Evolution: add optional fields only. Approval tests (MessageContractTests) snapshot every contract, so a change shows up in review. Removing or renaming a field needs a new message type.
  • Docs: every contract has a page here. The field tables are generated from the C# XML docs (python3 build/docs/event-pages.py), and EventDocsTests fails the build when a page is missing or stale.