MXMessage
A Rust library for parsing, validating, and serializing ISO 20022 (MX) financial messages.
Full CBPR+ compliance with comprehensive validation and test data generation.
MXMessage is a comprehensive Rust library for handling ISO 20022 (MX) financial messages. It provides type-safe parsing, validation, and serialization for CBPR+ compliant messages, with powerful test data generation capabilities for all supported message types.
๐ Key Features
- CBPR+ SR2025 Compliant: Full support for Central Bank Payment Regulation Plus SR2025 schemas.
- Simplified v3 API: Two main functions (
to_jsonandto_xml) handle all message types with automatic envelope generation. - Type-Safe: Strongly typed Rust structures generated from official XSD schemas.
- Comprehensive Validation: Field-level, pattern, and business rule validation with detailed error codes.
- Complete MX XML Generation: Automatic ISO 20022 compliant XML with proper AppHdr envelope.
- Multiple Formats: Native support for both JSON and XML serialization.
- Test Data Generation: Automatic generation of valid test messages using configurable scenarios.
- Extensive Coverage: Support for pacs, pain, and camt message families.
- Zero-Copy Parsing: Efficient processing with minimal allocations.
- Dataflow Integration: Plugin support for dataflow-rs engine enabling async processing pipelines.
- Enhanced XML Support: Advanced XML serialization with configurable formatting and namespace handling.
๐๏ธ How It Works: Schema-Driven Architecture
Generated Types from XSD
All message types are automatically generated from official ISO 20022 XSD schemas.
use Document;
use *;
// Create a strongly-typed payment message
let payment = FIToFICustomerCreditTransferV08 ;
// Automatic validation
match FIToFICustomerCreditTransferV08.validate
Message Families
// Payment messages
use Document;
use *; // Customer Credit Transfer
use *; // Financial Institution Credit Transfer
// Cash management messages
use *; // Bank to Customer Statement
use *; // Payment Cancellation Request
// Payment initiation messages
use *; // Customer Credit Transfer Initiation
use *; // Customer Direct Debit Initiation
๐ฏ Serialization Support
MXMessage provides seamless serialization between JSON and XML formats with enhanced XML capabilities.
use Document;
use ;
use serde_json;
// Parse from JSON
let doc: Document = from_str?;
// Serialize to pretty JSON
let json_output = to_string_pretty?;
// Enhanced XML serialization with configuration
let xml_config = XmlConfig ;
// Generate complete MX XML with envelope
let xml_output = to_mx_xml?;
Example JSON Output:
๐ง Installation
Add mx-message to your Cargo.toml:
[]
= "3.1"
= "1.0" # For JSON support
= { = "0.38", = ["serialize"] } # For XML support
# Optional: For dataflow pipeline integration
= "2.0" # For async processing pipelines
= "4.0" # For validation logic
๐ Usage
Basic Message Creation (v3 API)
use ;
use Document;
use *;
// Create a payment message
let payment = FIToFICustomerCreditTransferV08 ;
let document = FIToFICustomerCreditTransferV08;
// Validate against CBPR+ SR2025 rules
match document.validate
// Convert to JSON (simplified v3 API)
let json = to_json?;
println!;
// Convert to XML with automatic envelope (simplified v3 API)
let xml = to_xml?;
println!;
Test Data Generation
use generate_sample;
// Generate test data from scenario files
let sample = generate_sample?;
println!;
// Scenarios support fake data generation
// See test_scenarios/ directory for examples
Complete MX XML Generation (v3 Simplified API)
Generate ISO 20022 compliant XML with proper envelope and Business Application Header using the simplified v3 API:
use ;
use Document;
// Create or load your message
let document = FIToFICustomerCreditTransferV08;
// Convert to JSON - simple one-liner
let json = to_json?;
println!;
// Convert to XML with automatic envelope generation
let xml = to_xml?;
println!;
The v3 API automatically:
- Generates the correct Business Application Header based on message type
- Creates a properly formatted MX envelope with AppHdr
- Sets appropriate namespaces and CBPR+ compliance indicators
- Handles all message types uniformly
Note: The simplified API uses sensible defaults. For advanced customization of headers and envelopes, the lower-level APIs are still available:
use create_mx_envelope;
use BusinessApplicationHeaderV02;
// Create custom header for advanced use cases
let custom_header = BusinessApplicationHeaderV02 ;
// Create envelope with custom header
let envelope = create_mx_envelope?;
let xml = to_string?;
Validation Error Handling
use Document;
match document.validate
Dataflow Integration (New in v3.1)
MXMessage now provides seamless integration with dataflow-rs for building async processing pipelines with a clean, refactored plugin architecture:
use register_mx_functions;
use Engine;
// Register MX message functions with dataflow engine
let functions = register_mx_functions;
let mut engine = new;
for in functions
// Create a pipeline workflow
let workflow = r#"
{
"name": "mx-processing-pipeline",
"tasks": [
{
"id": "generate",
"function": "generate_mx",
"params": {
"message_type": "pacs.008",
"scenario": "cbpr_business_payment"
}
},
{
"id": "validate",
"function": "validate_mx",
"inputs": ["generate.output"]
},
{
"id": "publish",
"function": "publish_mx",
"params": {
"format": "xml"
},
"inputs": ["validate.output"]
}
]
}
"#;
// Execute the pipeline asynchronously
let result = engine.execute.await?;
Available dataflow functions:
parse_mx: Parse MX messages from JSON/XMLvalidate_mx: Validate against schema and business rulesgenerate_mx: Generate sample data from scenariospublish_mx: Serialize to JSON/XML formats
The plugin architecture has been refactored for better maintainability:
- Common utilities module (
plugin::common) provides shared functionality - Centralized format detection and message type mapping
- Reduced code duplication across plugin modules
- Type-safe error handling with improved error types
Error Collection (Comprehensive Validation)
MXMessage supports collecting all validation errors instead of stopping at the first error:
use Validate;
use ;
use FIToFICustomerCreditTransferV08;
// Create a message with multiple validation issues
let payment = FIToFICustomerCreditTransferV08 ;
// Collect all validation errors
let config = default;
let mut collector = new;
payment.validate;
// Process all errors at once
if collector.has_errors else
๐งช Testing Strategy
MXMessage uses comprehensive testing with 168 real-world scenarios migrated from MT messages, covering cross-border payments, securities, cash management, and more.
Key Testing Features
- Scenario-Based Testing: 168 scenarios across 16 message types
- Round-Trip Validation: JSON โ Generate โ Validate โ JSON testing
- MT to MX Migration: 99.4% coverage of MT message scenarios
- Sample Generation: Automatic test data using
datafakelibrary - 100% Success Rate: All 1,680 tests pass (10 samples per scenario)
Quick Start
# Run all test scenarios
# Test specific message type
TEST_MESSAGE_TYPE=pacs.008
# Debug a specific scenario
TEST_MESSAGE_TYPE=pacs.008 TEST_SCENARIO=cbpr_cross_border_payment TEST_DEBUG=1
For detailed test scenarios and MT to MX mapping, see the Test Scenarios Documentation.
๐๏ธ CBPR+ SR2025 Compliance
This library implements CBPR+ SR2025 (Central Bank Payment Regulation Plus Standards Release 2025) compliant schemas, providing:
- Enhanced Validation: Stricter rules for regulatory compliance
- UETR Support: Unique End-to-end Transaction Reference tracking
- Central Bank Integration: Support for central bank payment systems
- Cross-Border Payments: Full support for international transactions
- Regulatory Reporting: Compliance with reporting requirements
- BizSvc SR2025: Updated Business Service identifier
swift.cbprplus.02for SR2025 compliance
๐ Supported Message Types
Payment Messages (pacs)
- pacs.002.001.10: Payment Status Report
- pacs.003.001.08: Direct Debit
- pacs.004.001.09: Payment Return
- pacs.008.001.08: Customer Credit Transfer
- pacs.009.001.08: Financial Institution Credit Transfer
- pacs.010.001.03: Financial Institution Direct Debit (New in v3.1)
Payment Initiation (pain)
- pain.001.001.09: Customer Credit Transfer Initiation
- pain.008.001.08: Customer Direct Debit Initiation
Cash Management (camt)
- camt.025.001.05: Receipt
- camt.027.001.07: Claim Non Receipt
- camt.028.001.09: Additional Payment Information
- camt.029.001.09: Resolution of Investigation
- camt.052.001.08: Bank to Customer Account Report
- camt.053.001.08: Bank to Customer Statement
- camt.054.001.08: Bank to Customer Debit/Credit Notification
- camt.056.001.08: Payment Cancellation Request
- camt.057.001.06: Notification to Receive
- camt.060.001.05: Account Reporting Request
- camt.107.001.01: Cheque Presentment Notification (New in v3.1)
- camt.108.001.01: Cheque Stop Request (New in v3.1)
- camt.109.001.01: Cheque Cancellation or Stop Request Status (New in v3.1)
๐ค Contributing
Contributions are welcome! If you'd like to help, please feel free to fork the repository, make your changes, and submit a pull request. We ask that you:
- Ensure all new message types follow CBPR+ compliance standards
- Add comprehensive tests for new functionality
- Update documentation for any new features
- Follow existing code style and validation patterns
๐ข About Plasmatic
MXMessage is developed by Plasmatic, an organization focused on building open-source tools for financial infrastructure. We believe in transparency, security, and performance.
Check out our other projects:
- SwiftMTMessage: A SWIFT MT message parsing library.
- Reframe: A SWIFT MT to ISO 20022 (and back) transformation engine.
๐ License
This library is licensed under the Apache License, Version 2.0. See the LICENSE file for details.