Skip to content

feat: Implement ProcessWorker for message consumption#142

Merged
artcava merged 7 commits intodevelopfrom
feature/99-process-worker-message-consumption
Mar 2, 2026
Merged

feat: Implement ProcessWorker for message consumption#142
artcava merged 7 commits intodevelopfrom
feature/99-process-worker-message-consumption

Conversation

@artcava
Copy link
Copy Markdown
Owner

@artcava artcava commented Mar 2, 2026

Description

Implements the background worker for consuming and processing messages from RabbitMQ queue, completing the asynchronous process execution pipeline.

Changes

Core Domain

  • ProcessContext: New domain model for handler execution context with metadata support and cancellation token
  • ProcessMessage.Metadata: Added metadata property for message routing and tracking

Server Components

  • ProcessWorker: Background service implementing BackgroundService for long-running message consumption
    • Integrates with IMessageConsumer using callback pattern
    • Full ACK/NACK strategy with MessageContext.AcknowledgeAsync() and RejectAsync()
    • Comprehensive error handling with retriable vs non-retriable distinction
    • Graceful shutdown support
    • Separate handling for deserialization errors (JsonException)

Testing

  • ProcessWorkerTests: Unit tests covering constructor validation and basic lifecycle

Configuration

  • Program.cs: Registered ProcessWorker as hosted service

Architecture Notes

  • Uses IProcessService facade instead of direct repository access for better separation of concerns
  • Leverages existing MessageContext with delegate-based ACK/NACK
  • Compatible with existing RabbitMqConsumer implementation
  • ProcessContext created but not yet integrated (reserved for future handler enhancement)

Message Flow

RabbitMQ → ProcessMessage → Deserialize → TransitionToProcessing
    ↓
GetHandler → ExecuteAsync → CompleteProcess → ACK
    ↓
Error (retriable) → FailProcess → NACK(requeue=true)
Error (non-retriable) → FailProcess → NACK(requeue=false)
JsonException → NACK(requeue=false) → DLQ

Testing

  • ✅ Unit tests pass
  • ✅ Project compiles successfully
  • ⏳ Integration tests pending (requires RabbitMQ instance)

Related Issues

Closes #99

Checklist

  • Code follows project coding conventions
  • Self-review completed
  • Comments added for complex logic
  • Unit tests added/updated
  • All tests passing locally
  • No new warnings introduced
  • Documentation updated (if needed)
  • Integration tests performed (pending infrastructure)

Breaking Changes

None

Migration Notes

No migration required. The worker is automatically registered and will start consuming messages when the Server application starts.

artcava and others added 7 commits March 2, 2026 09:26
- Create ProcessContext class with process metadata
- Add helper methods for metadata management
- Provide cancellation token for cooperative cancellation
- Document purpose and usage in XML comments

Related to #99
- Add Metadata dictionary to ProcessMessage
- Update FromProcess to include metadata
- Maintain JSON property naming for serialization

Related to #99
- Create ProcessWorker as BackgroundService
- Integrate IMessageConsumer for message consumption
- Implement process lifecycle management
- Add comprehensive error handling with ACK/NACK logic
- Support graceful shutdown
- Add detailed logging for operations
- Handle deserialiation errors separately

Related to #99
- Process domain entity does not have Metadata property
- Metadata is only part of the message, not persisted in Process
- Initialize Metadata to null in FromProcess

Fixes compilation error CS1061

Related to #99
- Use AcknowledgeAsync instead of AckAsync
- Use RejectAsync instead of NackAsync
- RejectAsync accepts bool parameter for requeue
- Methods are Func properties that need to be invoked

Fixes compilation errors CS1061

Related to #99
- Replace IProcessRepository and IPolicyProvider with IProcessService
- Update all test cases to use correct constructor signature
- Fix parameter names in ArgumentNullException tests
- Update StartConsumingAsync type to ProcessMessage

Related to #99
@artcava artcava merged commit c5d415d into develop Mar 2, 2026
4 checks passed
@artcava artcava deleted the feature/99-process-worker-message-consumption branch March 2, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant