@mojaloop/central-ledger 19.14.0 → 20.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.grype.yaml +3 -0
- package/.license-scanner.json +16 -0
- package/.ncurc.yaml +19 -13
- package/.nvmrc +1 -1
- package/.nycrc.yml +14 -2
- package/CHANGELOG.md +51 -0
- package/Dockerfile +13 -10
- package/README.md +39 -89
- package/audit-ci.jsonc +1 -1
- package/config/default.json +60 -3
- package/config/deprecated.default-settlement.json +160 -0
- package/docker/ml-api-adapter/default.json +28 -0
- package/docker-compose.yml +6 -0
- package/nodemon.json +6 -0
- package/package.json +128 -64
- package/{sbom-v19.13.2.csv → sbom-v20.0.0.csv} +886 -736
- package/scripts/_wait4_all.js +5 -5
- package/scripts/transferSettlementTemp/interchangeFeeCalculation.js +51 -0
- package/src/api/index.ts +30 -0
- package/src/api/interface/swagger.json +2249 -2054
- package/src/api/participants/routes.js +1 -1
- package/src/api/root/handler.int.ts +55 -0
- package/src/api/routes.js +7 -6
- package/src/api/server.ts +27 -0
- package/src/api/server.unit.ts +16 -0
- package/src/api/settlementModels/routes.js +4 -4
- package/src/domain/participant/index.d.ts +47 -0
- package/src/domain/participant/index.int.ts +724 -0
- package/src/domain/participant/index.js +4 -5
- package/src/domain/position/fx-prepare.js +1 -1
- package/src/domain/position/fx-timeout-reserved.js +6 -0
- package/src/domain/position/prepare.js +1 -1
- package/src/handlers/admin/handler.js +1 -1
- package/src/handlers/index.js +30 -0
- package/src/handlers/positions/handler.js +0 -2
- package/src/handlers/positions/handlerBatch.js +5 -5
- package/src/handlers/register.js +44 -29
- package/src/handlers/timeouts/handler.js +1 -4
- package/src/handlers/transfers/fx-abort.int.ts +209 -0
- package/src/handlers/transfers/fx-handlers.int.ts +275 -0
- package/src/handlers/transfers/fx-timeout.int.ts +284 -0
- package/src/handlers/transfers/handler.js +1 -3
- package/src/handlers/transfers/handlers.int.ts +538 -0
- package/src/handlers/transfers/prepare.int.ts +1283 -0
- package/src/handlers/transfers/prepare.js +2 -2
- package/src/knexfile.js +19 -0
- package/src/lib/cache.js +1 -1
- package/src/lib/config/index.ts +60 -0
- package/src/lib/config/resolver.ts +231 -0
- package/src/lib/config/resolver.unit.ts +72 -0
- package/src/lib/config/types.ts +372 -0
- package/src/lib/config/util.ts +523 -0
- package/src/lib/config/util.unit.ts +825 -0
- package/src/lib/migrator.js +3 -3
- package/src/lib/proxyCache.js +3 -3
- package/{migrations → src/migrations}/100100_event.js +1 -1
- package/{migrations → src/migrations}/110100_contactType.js +1 -1
- package/{migrations → src/migrations}/110200_currency.js +1 -1
- package/{migrations → src/migrations}/110201_currency-scale.js +1 -1
- package/{migrations → src/migrations}/110300_endpointType.js +1 -1
- package/{migrations → src/migrations}/110400_ledgerEntryType.js +1 -1
- package/{migrations → src/migrations}/110450_ledgerAccountType.js +1 -1
- package/{migrations → src/migrations}/110500_participantLimitType.js +1 -1
- package/{migrations → src/migrations}/110600_transferParticipantRoleType.js +1 -1
- package/{migrations → src/migrations}/110700_transferState.js +1 -1
- package/{migrations → src/migrations}/110900_settlementState.js +1 -1
- package/{migrations → src/migrations}/112000_bulkTransferState.js +1 -1
- package/{migrations → src/migrations}/112100_bulkProcessingState.js +1 -1
- package/{migrations → src/migrations}/200100_participant.js +1 -1
- package/{migrations → src/migrations}/200200_participantContact.js +1 -1
- package/{migrations → src/migrations}/200300_participantEndpoint.js +1 -1
- package/{migrations → src/migrations}/200400_participantParty.js +1 -1
- package/{migrations → src/migrations}/200600_token.js +1 -1
- package/{migrations → src/migrations}/200601_token-indexes.js +1 -1
- package/{migrations → src/migrations}/300100_transferDuplicateCheck.js +2 -2
- package/{migrations → src/migrations}/300150_bulkTransferDuplicateCheck.js +2 -2
- package/{migrations → src/migrations}/300200_transfer.js +2 -2
- package/{migrations → src/migrations}/300202_transfer-decimal184.js +1 -1
- package/{migrations → src/migrations}/300250_bulkTransfer.js +2 -3
- package/{migrations → src/migrations}/300275_bulkTransferAssociation.js +2 -3
- package/{migrations → src/migrations}/300300_ilpPacket.js +1 -1
- package/{migrations → src/migrations}/300400_transferStateChange.js +1 -1
- package/{migrations → src/migrations}/300450_bulkTransferStateChange.js +1 -1
- package/{migrations → src/migrations}/300500_segment.js +1 -1
- package/{migrations → src/migrations}/310100_participantCurrency.js +1 -1
- package/{migrations → src/migrations}/310200_transferParticipant.js +1 -1
- package/{migrations → src/migrations}/310202_transferParticipant-decimal184.js +1 -1
- package/{migrations → src/migrations}/310204_transferParticipant-participantId.js +2 -2
- package/{migrations → src/migrations}/310300_participantPosition.js +1 -1
- package/{migrations → src/migrations}/310302_participantPosition-decimal184.js +1 -1
- package/{migrations → src/migrations}/310400_participantPositionChange.js +1 -1
- package/{migrations → src/migrations}/310402_participantPositionChange-decimal184.js +1 -1
- package/{migrations → src/migrations}/310403_participantPositionChange-participantCurrencyId.js +2 -2
- package/{migrations → src/migrations}/310404_participantPositionChange-change.js +2 -2
- package/{migrations → src/migrations}/310500_participantLimit.js +1 -1
- package/{migrations → src/migrations}/310502_participantLimit-decimal184.js +1 -1
- package/{migrations → src/migrations}/400100_settlementWindow.js +1 -1
- package/{migrations → src/migrations}/400200_settlement.js +1 -1
- package/{migrations → src/migrations}/400300_settlementSettlementWindow.js +1 -1
- package/{migrations → src/migrations}/400301_settlementSettlementWindow-indexes.js +0 -1
- package/{migrations → src/migrations}/400400_settlementWindowStateChange.js +1 -1
- package/{migrations → src/migrations}/400500_settlementTransferParticipant.js +1 -1
- package/{migrations → src/migrations}/400502_settlementTransferParticipant-decimal184.js +1 -1
- package/{migrations → src/migrations}/400600_settlementParticipantCurrency.js +1 -1
- package/{migrations → src/migrations}/400602_settlementParticipantCurrency-decimal184.js +1 -1
- package/{migrations → src/migrations}/400700_settlementParticipantCurrencyStateChange.js +1 -1
- package/{migrations → src/migrations}/400800_settlementStateChange.js +1 -1
- package/{migrations → src/migrations}/400900_settlementWindowContent.js +1 -1
- package/{migrations → src/migrations}/401000_settlementWindowContentStateChange.js +1 -1
- package/{migrations → src/migrations}/401001_settlementWindowContentStateChange-indexes.js +6 -6
- package/{migrations → src/migrations}/401200_settlementContentAggregation.js +1 -1
- package/{migrations → src/migrations}/401300_settlementModel.js +1 -1
- package/{migrations → src/migrations}/410100_transferFulfilmentDuplicateCheck.js +1 -1
- package/{migrations → src/migrations}/410102_transferFulfilmentDuplicateCheck-dropForeignTransferId.js +1 -1
- package/{migrations → src/migrations}/410103_transferFulfilmentDuplicateCheck-hashNullable.js +1 -1
- package/{migrations → src/migrations}/410200_transferFulfilment.js +1 -1
- package/{migrations → src/migrations}/410202_transferFulfilment-ilpFulfilment.js +1 -1
- package/{migrations → src/migrations}/410203_transferFulfilment-foreignTransferFulfilmentId.js +1 -1
- package/{migrations → src/migrations}/410240_bulkTransferFulfilmentDuplicateCheck.js +1 -1
- package/{migrations → src/migrations}/410250_bulkTransferFulfilment.js +1 -1
- package/{migrations → src/migrations}/410300_transferExtension.js +1 -1
- package/{migrations → src/migrations}/410302_transferExtension-transferErrorId.js +1 -1
- package/{migrations → src/migrations}/410350_bulkTransferExtension.js +1 -1
- package/{migrations → src/migrations}/410400_transferTimeout.js +1 -1
- package/{migrations → src/migrations}/410450_transferErrorDuplicateCheck.js +1 -1
- package/{migrations → src/migrations}/410500_transferError.js +1 -1
- package/{migrations → src/migrations}/410502_transferError-foreignTransferErrorDuplicateCheckId.js +1 -1
- package/{migrations → src/migrations}/410550_bulkTransferError.js +1 -1
- package/{migrations → src/migrations}/410600_expiringTransfer.js +1 -1
- package/{migrations → src/migrations}/500401_quote-hotfix-2719.js +8 -8
- package/{migrations → src/migrations}/500501_feature-fixSubIdRef.js +12 -12
- package/{migrations → src/migrations}/500601_party-2480.js +3 -3
- package/{migrations → src/migrations}/501001_quoteExtension-quote-service-174.js +1 -2
- package/{migrations → src/migrations}/501002_quoteExtension-2522.js +3 -3
- package/{migrations → src/migrations}/600010_fxTransferType.js +1 -1
- package/{migrations → src/migrations}/600012_fxParticipantCurrencyType.js +1 -1
- package/{migrations → src/migrations}/600100_fxTransferDuplicateCheck.js +2 -2
- package/{migrations → src/migrations}/600110_fxTransferErrorDuplicateCheck.js.js +1 -1
- package/{migrations → src/migrations}/600200_fxTransfer.js +2 -2
- package/{migrations → src/migrations}/600400_fxTransferStateChange.js +1 -1
- package/{migrations → src/migrations}/600501_fxWatchList.js +2 -2
- package/{migrations → src/migrations}/600600_fxTransferFulfilmentDuplicateCheck.js +1 -1
- package/{migrations → src/migrations}/600700_fxTransferFulfilment.js +1 -1
- package/{migrations → src/migrations}/600800_fxTransferExtension.js +1 -1
- package/{migrations → src/migrations}/601400_fxTransferTimeout.js +1 -1
- package/{migrations → src/migrations}/601500_fxTransferError.js +1 -1
- package/{migrations → src/migrations}/610200_fxTransferParticipant.js +1 -1
- package/{migrations → src/migrations}/610202_fxTransferParticipant-participantId.js +2 -2
- package/{migrations → src/migrations}/610403_participantPositionChange-fxTransfer.js +1 -1
- package/{migrations → src/migrations}/800100_quotePartyView.js +1 -1
- package/{migrations → src/migrations}/800101_feature-fixSubIdRef.js +1 -1
- package/{migrations → src/migrations}/800200_quoteView.js +1 -1
- package/{migrations → src/migrations}/800300_quoteResponseView.js +1 -1
- package/{migrations → src/migrations}/900100_foreign-keys.js +18 -18
- package/{migrations → src/migrations}/900101_foreign-keys.js +6 -6
- package/{migrations → src/migrations}/910100_feature904DDL.js +7 -7
- package/{migrations → src/migrations}/910101_feature904DataMigration.js +1 -1
- package/{migrations → src/migrations}/910102_feature949DataMigration.js +1 -1
- package/{migrations → src/migrations}/910103_feature1093SettlementByCurrency.js +3 -3
- package/{migrations → src/migrations}/940101_quotePartyIdInfoExtension-2522.js +25 -25
- package/{migrations → src/migrations}/950101_transferParticipantStateChange.js +2 -2
- package/{migrations → src/migrations}/950102_settlementModel-adjustPosition.js +2 -2
- package/{migrations → src/migrations}/950103_dropTransferParticipantStateChange.js +3 -3
- package/{migrations → src/migrations}/950104_settlementModel-settlementAccountTypeId.js +3 -3
- package/src/migrations/950107_settlementWindowContent_foreign_settlementModel.js +63 -0
- package/{migrations → src/migrations}/950108_participantProxy.js +1 -2
- package/{migrations → src/migrations}/950120_fxQuoteConversionTerms_sourceAmount_nullable.js +1 -1
- package/{migrations → src/migrations}/960100_create_externalParticipant.js +2 -2
- package/{migrations → src/migrations}/960110_alter_transferParticipant__addFiled_externalParticipantId.js +2 -2
- package/{migrations → src/migrations}/961001_transferForwarded.js +1 -1
- package/{migrations → src/migrations}/961002_fxTransferForwarded.js +1 -1
- package/src/models/participant/externalParticipant.int.ts +85 -0
- package/src/models/participant/facade.js +4 -2
- package/src/models/participant/participantCurrencyCached.js +1 -1
- package/src/models/position/facade.js +8 -2
- package/src/models/transfer/facade.int.ts +139 -0
- package/src/models/transfer/facade.js +8 -3
- package/src/models/transfer/transferDuplicateCheck.js +2 -2
- package/src/models/transfer/transferError.int.ts +112 -0
- package/src/models/transfer/transferExtension.int.ts +137 -0
- package/src/models/transfer/transferStateChange.int.ts +117 -0
- package/{seeds → src/seeds}/participant.js +1 -1
- package/{seeds → src/seeds}/settlementInterchange.js +1 -0
- package/src/settlement/api/handlerRoutes.js +71 -0
- package/src/settlement/api/handlers/health.js +10 -0
- package/src/settlement/api/handlers/index.js +57 -0
- package/src/settlement/api/handlers/settlementWindows/{id}.js +103 -0
- package/src/settlement/api/handlers/settlementWindows.js +77 -0
- package/src/settlement/api/handlers/settlements/{id}.js +133 -0
- package/src/settlement/api/handlers/settlements/{sid}/participants/{pid}/accounts/{aid}.js +127 -0
- package/src/settlement/api/handlers/settlements/{sid}/participants/{pid}.js +127 -0
- package/src/settlement/api/handlers/settlements.js +114 -0
- package/src/settlement/api/openapiRouting.js +87 -0
- package/src/settlement/api/routes.js +176 -0
- package/src/settlement/domain/rules/index.js +46 -0
- package/src/settlement/domain/settlement/index.js +405 -0
- package/src/settlement/domain/settlementWindow/index.js +117 -0
- package/src/settlement/domain/transactions/index.js +83 -0
- package/src/settlement/domain/transferSettlement/index.js +57 -0
- package/src/settlement/handlers/deferredSettlement/handler.js +180 -0
- package/src/settlement/handlers/grossSettlement/handler.js +180 -0
- package/src/settlement/handlers/index.js +101 -0
- package/src/settlement/handlers/register.js +92 -0
- package/src/settlement/handlers/rules/handler.js +164 -0
- package/src/settlement/interface/swagger-handler.json +34 -0
- package/src/settlement/interface/swagger.json +1560 -0
- package/src/settlement/lib/db.js +32 -0
- package/src/settlement/lib/kafka/index.js +41 -0
- package/src/settlement/lib/kafka/producer.js +142 -0
- package/src/settlement/lib/scriptEngine.js +99 -0
- package/src/settlement/lib/scriptsLoader.js +175 -0
- package/src/settlement/lib/utility.js +243 -0
- package/src/settlement/models/ilpPackets/ilpPacket.js +42 -0
- package/src/settlement/models/lib/enums.js +192 -0
- package/src/settlement/models/misc/migrationLock.js +53 -0
- package/src/settlement/models/settlement/facade.js +1652 -0
- package/src/settlement/models/settlement/index.js +55 -0
- package/src/settlement/models/settlement/participantCurrency.js +48 -0
- package/src/settlement/models/settlement/settlement.js +49 -0
- package/src/settlement/models/settlement/settlementModel.js +44 -0
- package/src/settlement/models/settlement/settlementParticipantCurrency.js +61 -0
- package/src/settlement/models/settlement/settlementStateChange.js +44 -0
- package/src/settlement/models/settlement/settlementTransferParticipant.js +46 -0
- package/src/settlement/models/settlementWindow/facade.js +345 -0
- package/src/settlement/models/settlementWindow/index.js +47 -0
- package/src/settlement/models/settlementWindow/settlementWindowStateChange.js +55 -0
- package/src/settlement/models/settlementWindowContent/facade.js +79 -0
- package/src/settlement/models/settlementWindowContent/index.js +40 -0
- package/src/settlement/models/settlementWindowContent/settlementWindowContentStateChange.js +53 -0
- package/src/settlement/models/transferSettlement/facade.js +363 -0
- package/src/settlement/models/transferSettlement/index.js +42 -0
- package/src/settlement/shared/logger/index.js +7 -0
- package/src/settlement/shared/plugins.js +88 -0
- package/src/settlement/shared/setup.js +224 -0
- package/src/settlement/utils/truthyProperty.js +37 -0
- package/src/shared/legacyUtilShim.js +20 -0
- package/src/shared/plugins.js +3 -3
- package/src/shared/results.ts +22 -0
- package/src/shared/results.unit.ts +38 -0
- package/src/shared/setup.js +14 -1
- package/src/testing/api-helpers.ts +1222 -0
- package/src/testing/exec-async.ts +67 -0
- package/src/testing/harness.snapshot.sql +3895 -0
- package/src/testing/harness.test.ts +15 -0
- package/src/testing/harness.ts +1160 -0
- package/src/testing/kafka.ts +221 -0
- package/src/testing/prng.ts +82 -0
- package/src/testing/rdkafka.test.ts +263 -0
- package/src/testing/run.ts +559 -0
- package/src/testing/snapshot.test.ts +92 -0
- package/src/testing/snapshot.ts +549 -0
- package/src/testing/tap-stream.ts +164 -0
- package/src/testing/types.ts +95 -0
- package/src/testing/util.ts +333 -0
- package/src/types/central-services-error-handling.d.ts +72 -0
- package/src/types/central-services-stream.d.ts +148 -0
- package/test-integration.Dockerfile +0 -2
- package/test.Dockerfile +0 -2
- package/tsconfig.json +40 -0
- package/config/knexfile.js +0 -19
- package/migrations/950107_settlementWindowContent_foreign_settlementModel.js +0 -63
- package/src/api/index.js +0 -16
- package/src/lib/config.js +0 -81
- /package/{migrations → src/migrations}/110101_contactType-indexes.js +0 -0
- /package/{migrations → src/migrations}/110301_endpointType-indexes.js +0 -0
- /package/{migrations → src/migrations}/110401_ledgerEntryType-indexes.js +0 -0
- /package/{migrations → src/migrations}/110451_ledgerAccountType-indexes.js +0 -0
- /package/{migrations → src/migrations}/110501_participantLimitType-indexes.js +0 -0
- /package/{migrations → src/migrations}/110601_transferParticipantRoleType-indexes.js +0 -0
- /package/{migrations → src/migrations}/110800_settlementWindowState.js +0 -0
- /package/{migrations → src/migrations}/111000_amountType.js +0 -0
- /package/{migrations → src/migrations}/111001_amountType-indexes.js +0 -0
- /package/{migrations → src/migrations}/111100_balanceOfPayments.js +0 -0
- /package/{migrations → src/migrations}/111101_balanceOfPayments-indexes.js +0 -0
- /package/{migrations → src/migrations}/111200_partyIdentifierType.js +0 -0
- /package/{migrations → src/migrations}/111201_partyIdentifierType-indexes.js +0 -0
- /package/{migrations → src/migrations}/111300_partyType.js +0 -0
- /package/{migrations → src/migrations}/111301_partyType-indexes.js +0 -0
- /package/{migrations → src/migrations}/111400_quoteDuplicateCheck.js +0 -0
- /package/{migrations → src/migrations}/111500_transactionInitiator.js +0 -0
- /package/{migrations → src/migrations}/111501_transactionInitiator-indexes.js +0 -0
- /package/{migrations → src/migrations}/111600_transactionInitiatorType.js +0 -0
- /package/{migrations → src/migrations}/111601_transactionInitiatorType-indexes.js +0 -0
- /package/{migrations → src/migrations}/111700_settlementDelay.js +0 -0
- /package/{migrations → src/migrations}/111701_settlementDelay-indexes.js +0 -0
- /package/{migrations → src/migrations}/111800_settlementInterchange.js +0 -0
- /package/{migrations → src/migrations}/111801_settlementInterchange-indexes.js +0 -0
- /package/{migrations → src/migrations}/111900_settlementGranularity.js +0 -0
- /package/{migrations → src/migrations}/111901_settlementGranularity-indexes.js +0 -0
- /package/{migrations → src/migrations}/112101_bulkProcessingState-indexes.js +0 -0
- /package/{migrations → src/migrations}/200101_participant-indexes.js +0 -0
- /package/{migrations → src/migrations}/200201_participantContact-indexes.js +0 -0
- /package/{migrations → src/migrations}/200301_participantEndpoint-indexes.js +0 -0
- /package/{migrations → src/migrations}/200401_participantParty-indexes.js +0 -0
- /package/{migrations → src/migrations}/300201_transfer-indexes.js +0 -0
- /package/{migrations → src/migrations}/300251_bulkTransfer-indexes.js +0 -0
- /package/{migrations → src/migrations}/300276_bulkTransferAssociation-indexes.js +0 -0
- /package/{migrations → src/migrations}/300401_transferStateChange-indexes.js +0 -0
- /package/{migrations → src/migrations}/300451_bulkTransferStateChange-indexes.js +0 -0
- /package/{migrations → src/migrations}/300501_segment-indexes.js +0 -0
- /package/{migrations → src/migrations}/310101_participantCurrency-indexes.js +0 -0
- /package/{migrations → src/migrations}/310201_transferParticipant-indexes.js +0 -0
- /package/{migrations → src/migrations}/310203_transferParticipant-indexes.js +0 -0
- /package/{migrations → src/migrations}/310301_participantPosition-indexes.js +0 -0
- /package/{migrations → src/migrations}/310401_participantPositionChange-indexes.js +0 -0
- /package/{migrations → src/migrations}/310405_participantPositionChange-positionChange.js +0 -0
- /package/{migrations → src/migrations}/310406_participantPositionChange-positionChange-revert.js +0 -0
- /package/{migrations → src/migrations}/310501_participantLimit-indexes.js +0 -0
- /package/{migrations → src/migrations}/310503_participantLimit-indexes-composite.js +0 -0
- /package/{migrations → src/migrations}/400401_settlmentWindowStateChange-indexes.js +0 -0
- /package/{migrations → src/migrations}/400501_settlementTransferParticipant-indexes.js +0 -0
- /package/{migrations → src/migrations}/400601_settlementParticipantCurrency-indexes.js +0 -0
- /package/{migrations → src/migrations}/400701_settlementParticipantCurrencyStateChange-indexes.js +0 -0
- /package/{migrations → src/migrations}/400801_settlementStateChange-indexes.js +0 -0
- /package/{migrations → src/migrations}/401002_settlementWindowContent-indexes.js +0 -0
- /package/{migrations → src/migrations}/401201_settlementContentAggregation-indexes.js +0 -0
- /package/{migrations → src/migrations}/401301_settlementModel-indexes.js +0 -0
- /package/{migrations → src/migrations}/410101_transferFulfilmentDuplicateCheck-indexes.js +0 -0
- /package/{migrations → src/migrations}/410201_transferFulfilment-indexes.js +0 -0
- /package/{migrations → src/migrations}/410301_transferExtension-indexes.js +0 -0
- /package/{migrations → src/migrations}/410351_bulkTransferExtension-indexes.js +0 -0
- /package/{migrations → src/migrations}/410401_transferTimeout-indexes.js +0 -0
- /package/{migrations → src/migrations}/410501_transferError-indexes.js +0 -0
- /package/{migrations → src/migrations}/410551_bulkTransferError-indexes.js +0 -0
- /package/{migrations → src/migrations}/410601_expiringTransfer-indexes.js +0 -0
- /package/{migrations → src/migrations}/500100_transactionReference.js +0 -0
- /package/{migrations → src/migrations}/500101_transactionReference-indexes.js +0 -0
- /package/{migrations → src/migrations}/500200_transactionScenario.js +0 -0
- /package/{migrations → src/migrations}/500201_transactionScenario-indexes.js +0 -0
- /package/{migrations → src/migrations}/500300_transactionSubScenario.js +0 -0
- /package/{migrations → src/migrations}/500400_quote.js +0 -0
- /package/{migrations → src/migrations}/500500_quoteParty.js +0 -0
- /package/{migrations → src/migrations}/500600_party.js +0 -0
- /package/{migrations → src/migrations}/500700_quoteResponse.js +0 -0
- /package/{migrations → src/migrations}/500800_quoteResponseIlpPacket.js +0 -0
- /package/{migrations → src/migrations}/500900_geoCode.js +0 -0
- /package/{migrations → src/migrations}/501000_quoteExtension.js +0 -0
- /package/{migrations → src/migrations}/501100_quoteResponseDuplicateCheck.js +0 -0
- /package/{migrations → src/migrations}/501200_quoteError.js +0 -0
- /package/{migrations → src/migrations}/501300_transferRules.js +0 -0
- /package/{migrations → src/migrations}/600011_fxTransferType-indexes.js +0 -0
- /package/{migrations → src/migrations}/600013_fxParticipantCurrencyType-indexes.js +0 -0
- /package/{migrations → src/migrations}/600201_fxTransfer-indexes.js +0 -0
- /package/{migrations → src/migrations}/600401_fxTransferStateChange-indexes.js +0 -0
- /package/{migrations → src/migrations}/600502_fxWatchList-indexes.js +0 -0
- /package/{migrations → src/migrations}/600601_fxTransferFulfilmentDuplicateCheck-indexes.js +0 -0
- /package/{migrations → src/migrations}/600701_fxTransferFulfilment-indexes.js +0 -0
- /package/{migrations → src/migrations}/601401_fxTransferTimeout-indexes.js +0 -0
- /package/{migrations → src/migrations}/601501_fxTransferError-indexes.js +0 -0
- /package/{migrations → src/migrations}/610201_fxTransferParticipant-indexes.js +0 -0
- /package/{migrations → src/migrations}/910102_hotfix954.js +0 -0
- /package/{migrations → src/migrations}/940100_quotePartyIdInfoExtension.js +0 -0
- /package/{migrations → src/migrations}/950100_settlementContentAggregation-decimal184.js +0 -0
- /package/{migrations → src/migrations}/950106_unique_settlement_model_ledger_account_currency.js +0 -0
- /package/{migrations → src/migrations}/950109_fxQuote.js +0 -0
- /package/{migrations → src/migrations}/950110_fxQuoteResponse.js +0 -0
- /package/{migrations → src/migrations}/950111_fxQuoteError.js +0 -0
- /package/{migrations → src/migrations}/950113_fxQuoteDuplicateCheck.js +0 -0
- /package/{migrations → src/migrations}/950114_fxQuoteResponseDuplicateCheck.js +0 -0
- /package/{migrations → src/migrations}/950115_fxQuoteConversionTerms.js +0 -0
- /package/{migrations → src/migrations}/950116_fxQuoteConversionTermsExtension.js +0 -0
- /package/{migrations → src/migrations}/950117_fxQuoteResponseConversionTerms.js +0 -0
- /package/{migrations → src/migrations}/950118_fxQuoteResponseConversionTermsExtension.js +0 -0
- /package/{migrations → src/migrations}/950119_fxCharge.js +0 -0
- /package/{migrations → src/migrations}/960111_alter_fxTransferParticipant__addFiled_externalParticipantId.js +0 -0
- /package/{migrations → src/migrations}/960112_fxTransfer-indexes2.js +0 -0
- /package/{migrations → src/migrations}/960113_fxTransferExtension-indexes.js +0 -0
- /package/{migrations → src/migrations}/960114_fxTransferTimeout-indexes2.js +0 -0
- /package/{migrations → src/migrations}/961000_participantEndpoint_unique.js +0 -0
- /package/{migrations → src/migrations}/migration.template +0 -0
- /package/{seeds → src/seeds}/amountType.js +0 -0
- /package/{seeds → src/seeds}/balanceOfPayments.js +0 -0
- /package/{seeds → src/seeds}/bulkProcessingState.js +0 -0
- /package/{seeds → src/seeds}/bulkTransferState.js +0 -0
- /package/{seeds → src/seeds}/currency.js +0 -0
- /package/{seeds → src/seeds}/endpointType.js +0 -0
- /package/{seeds → src/seeds}/fxParticipantCurrencyType.js +0 -0
- /package/{seeds → src/seeds}/fxTransferType.js +0 -0
- /package/{seeds → src/seeds}/ledgerAccountType.js +0 -0
- /package/{seeds → src/seeds}/ledgerEntryType.js +0 -0
- /package/{seeds → src/seeds}/participantLimitType.js +0 -0
- /package/{seeds → src/seeds}/partyIdentifierType.js +0 -0
- /package/{seeds → src/seeds}/partyType.js +0 -0
- /package/{seeds → src/seeds}/settlementDelay.js +0 -0
- /package/{seeds → src/seeds}/settlementGranularity.js +0 -0
- /package/{seeds → src/seeds}/settlementState.js +0 -0
- /package/{seeds → src/seeds}/settlementWindow1State.js +0 -0
- /package/{seeds → src/seeds}/settlementWindow2Open.js +0 -0
- /package/{seeds → src/seeds}/transactionInitiator.js +0 -0
- /package/{seeds → src/seeds}/transactionInitiatorType.js +0 -0
- /package/{seeds → src/seeds}/transactionScenario.js +0 -0
- /package/{seeds → src/seeds}/transferParticipantRoleType.js +0 -0
- /package/{seeds → src/seeds}/transferState.js +0 -0
- /package/{seeds → src/seeds}/z1000_settlementModel-deprecated.js- +0 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2026 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* TigerBeetle
|
|
23
|
+
- Lewis Daly <lewis@tigerbeetle.com>
|
|
24
|
+
--------------
|
|
25
|
+
|
|
26
|
+
******/
|
|
27
|
+
|
|
28
|
+
import Kafka from 'node-rdkafka'
|
|
29
|
+
import assert from "node:assert"
|
|
30
|
+
import Logger from "@mojaloop/central-services-logger"
|
|
31
|
+
|
|
32
|
+
const logger = Logger.child({ scope: 'testing/kafka' })
|
|
33
|
+
|
|
34
|
+
export class Producer {
|
|
35
|
+
private _producer: Kafka.HighLevelProducer
|
|
36
|
+
private _status: 'SETUP' | 'READY' | 'ERROR' | 'DISCONNECTED' = 'SETUP'
|
|
37
|
+
|
|
38
|
+
constructor(broker: string) {
|
|
39
|
+
this._producer = new Kafka.HighLevelProducer({
|
|
40
|
+
'metadata.broker.list': broker
|
|
41
|
+
})
|
|
42
|
+
// Seemed to be a good number in our local benchmarks.
|
|
43
|
+
this._producer.setPollInterval(50)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async connect(onError: (err: Kafka.LibrdKafkaError) => void): Promise<void> {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
this._producer.connect({}, (err, data) => {
|
|
49
|
+
if (err) {
|
|
50
|
+
this._status = 'ERROR'
|
|
51
|
+
logger.error(`Producer.connect() failed with error: ${err.message}.`)
|
|
52
|
+
return reject(err)
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
this._producer.on('ready', () => {
|
|
57
|
+
this._status = 'READY'
|
|
58
|
+
return resolve()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
this._producer.on('event.error', (err) => {
|
|
62
|
+
logger.error(`Producer on 'event.error': ${err.message}`)
|
|
63
|
+
onError(err)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
this._producer.setValueSerializer((value) => Buffer.from(value))
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async disconnect(): Promise<void> {
|
|
71
|
+
assert.equal(this._status, 'READY', 'Producer is not ready. Did you call `connect()`?')
|
|
72
|
+
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
this._producer.on('disconnected', () => {
|
|
75
|
+
resolve()
|
|
76
|
+
})
|
|
77
|
+
this._producer.flush()
|
|
78
|
+
this._producer.disconnect()
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Produce a set of messages to a topic.
|
|
84
|
+
*/
|
|
85
|
+
async produce(topic: string, messages: Array<any>): Promise<void> {
|
|
86
|
+
assert.equal(this._status, 'READY', 'Producer is not ready. Did you call `connect()`?')
|
|
87
|
+
|
|
88
|
+
const producePromise = (message: any): Promise<void> => new Promise((resolve, reject) => {
|
|
89
|
+
// Adding this into the hot path to more closely mimick the legacy kafka behaviour.
|
|
90
|
+
const messageStr = JSON.stringify(message)
|
|
91
|
+
this._producer.produce(topic, null, messageStr, null, Date.now(), (err, offset) => {
|
|
92
|
+
|
|
93
|
+
if (err) {
|
|
94
|
+
return reject(err)
|
|
95
|
+
}
|
|
96
|
+
return resolve()
|
|
97
|
+
})
|
|
98
|
+
})
|
|
99
|
+
const messagePromises = Promise.all(messages.map(message => producePromise(message)))
|
|
100
|
+
await messagePromises
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export class Consumer {
|
|
105
|
+
private _consumer: Kafka.KafkaConsumer
|
|
106
|
+
private _status: 'CREATED' | 'SUBSCRIBING' | 'CONSUMING' | 'ERRORED' | 'DISCONNECTED' = 'CREATED'
|
|
107
|
+
|
|
108
|
+
constructor(group: string, broker: string) {
|
|
109
|
+
assert(group)
|
|
110
|
+
assert(broker)
|
|
111
|
+
|
|
112
|
+
this._consumer = new Kafka.KafkaConsumer({
|
|
113
|
+
'group.id': group,
|
|
114
|
+
'enable.auto.commit': false,
|
|
115
|
+
'metadata.broker.list': broker,
|
|
116
|
+
'session.timeout.ms': 6000,
|
|
117
|
+
'heartbeat.interval.ms': 2000,
|
|
118
|
+
'socket.timeout.ms': 5000,
|
|
119
|
+
'fetch.wait.max.ms': 500,
|
|
120
|
+
}, {
|
|
121
|
+
'auto.offset.reset': 'earliest'
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public async subscribe(topics: Array<string | RegExp>, cb: (msg: Kafka.Message) => void): Promise<void> {
|
|
126
|
+
logger.debug(`Consumer.subscribe()`)
|
|
127
|
+
|
|
128
|
+
if (this._status !== 'CREATED') {
|
|
129
|
+
throw new Error(`Consumer.subscribe() - tried to subscribe but status was: ${this._status}.\
|
|
130
|
+
Expectected status: 'CREATED'.`)
|
|
131
|
+
}
|
|
132
|
+
this._status = 'SUBSCRIBING'
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
this._consumer.connect()
|
|
135
|
+
|
|
136
|
+
this._consumer.on('ready', (info, metadata) => {
|
|
137
|
+
this._consumer.subscribe(topics)
|
|
138
|
+
this._consumer.consume()
|
|
139
|
+
this._status = 'CONSUMING'
|
|
140
|
+
logger.debug(`Consumer subscribed and ready.`)
|
|
141
|
+
return resolve()
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
this._consumer.on('data', (msg) => {
|
|
145
|
+
return cb(msg)
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
this._consumer.on('event.error', (error: Kafka.LibrdKafkaError) => {
|
|
149
|
+
logger.error(`Consumer.on('event.error'): ${error.message}.`)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
this._consumer.on('connection.failure', (err) => {
|
|
153
|
+
this._status = 'ERRORED'
|
|
154
|
+
logger.error('connection failure', err);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
this._consumer.on('event.log', (log) => {
|
|
158
|
+
logger.info(log);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
this._consumer.on('disconnected', (msg) => {
|
|
162
|
+
this._status = 'DISCONNECTED'
|
|
163
|
+
logger.warn('disconnected', msg);
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
this._consumer.on('rebalance', (err, assignments) => {
|
|
167
|
+
logger.error('rebalance', err);
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Disconnect the consumer. Noop if not already consuming.
|
|
174
|
+
*/
|
|
175
|
+
public async disconnect(): Promise<void> {
|
|
176
|
+
logger.warn(`Consumer.disconnect()`)
|
|
177
|
+
const connected = this._consumer.isConnected()
|
|
178
|
+
|
|
179
|
+
if (!connected) {
|
|
180
|
+
logger.warn('Consumer already disconnected')
|
|
181
|
+
this._status = 'DISCONNECTED'
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (this._status !== 'CONSUMING') {
|
|
186
|
+
logger.warn(`Consumer.disconnect() called but status was: ${this._status}. Treating as a noop.`)
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const assignments = this._consumer.assignments()
|
|
191
|
+
if (assignments.length > 0) {
|
|
192
|
+
this._consumer.pause(assignments)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this._consumer.unsubscribe()
|
|
196
|
+
|
|
197
|
+
const timeoutMs = 10000
|
|
198
|
+
return new Promise((resolve, reject) => {
|
|
199
|
+
const timeout = setTimeout(() => {
|
|
200
|
+
const error = new Error(`Consumer.disconnect() timed out after: ${timeoutMs} ms`)
|
|
201
|
+
logger.error(error.message)
|
|
202
|
+
reject(error)
|
|
203
|
+
}, timeoutMs)
|
|
204
|
+
logger.info('calling _consumer.disconnect()')
|
|
205
|
+
|
|
206
|
+
this._consumer.disconnect((err: any, data: Kafka.ClientMetrics) => {
|
|
207
|
+
|
|
208
|
+
logger.info('_consumer.disconnect - callback!')
|
|
209
|
+
clearTimeout(timeout)
|
|
210
|
+
if (err) {
|
|
211
|
+
this._status = 'ERRORED'
|
|
212
|
+
return reject(err)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
this._status = 'DISCONNECTED'
|
|
216
|
+
return resolve()
|
|
217
|
+
})
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import assert from 'node:assert'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @class PRNG
|
|
5
|
+
* @description A seeded Progressive Random Number Generator. Useful for setting up fuzz tests etc.
|
|
6
|
+
* Reference: https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript
|
|
7
|
+
*/
|
|
8
|
+
export default class PRNG {
|
|
9
|
+
prng: () => number
|
|
10
|
+
|
|
11
|
+
constructor(seed: number) {
|
|
12
|
+
this.prng = splitmix32(seed)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public randomElementFrom<T>(array: Array<T>): T {
|
|
16
|
+
assert(array.length > 0, 'Expected array to have at least 1 element.')
|
|
17
|
+
const index = this.intExclusive(array.length)
|
|
18
|
+
return array[index]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public intExclusive(bound: number): number {
|
|
22
|
+
assert(typeof bound === 'number')
|
|
23
|
+
assert(bound > 0)
|
|
24
|
+
|
|
25
|
+
const max = 0xFFFFFFFF
|
|
26
|
+
const threshold = max - (max % bound)
|
|
27
|
+
|
|
28
|
+
while (true) {
|
|
29
|
+
const r = Math.floor(this.prng() * 0x100000000)
|
|
30
|
+
if (r < threshold) {
|
|
31
|
+
return r % bound
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public intInRange(min: number, max: number): number {
|
|
37
|
+
assert(max > min, 'Max must be greater than min.')
|
|
38
|
+
const range = max - min
|
|
39
|
+
return min + this.intExclusive(range)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public randomBytes(size: number): Buffer {
|
|
43
|
+
const buffer = Buffer.alloc(size)
|
|
44
|
+
for (let i = 0; i < size; i++) {
|
|
45
|
+
// Convert float [0,1) to int [0,255].
|
|
46
|
+
buffer[i] = Math.floor(this.prng() * 256)
|
|
47
|
+
}
|
|
48
|
+
return buffer
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public uuidv4(): string {
|
|
52
|
+
const buf = this.randomBytes(16)
|
|
53
|
+
// Set version (4) bits: byte 6 (index 6), bits 4 high bits.
|
|
54
|
+
buf[6] = (buf[6] & 0x0f) | 0x40
|
|
55
|
+
|
|
56
|
+
// Set variant bits: byte 8 (index 8), high 2 bits to 10.
|
|
57
|
+
buf[8] = (buf[8] & 0x3f) | 0x80
|
|
58
|
+
|
|
59
|
+
// Convert to UUID string.
|
|
60
|
+
const hex = buf.toString("hex")
|
|
61
|
+
|
|
62
|
+
return [
|
|
63
|
+
hex.substring(0, 8),
|
|
64
|
+
hex.substring(8, 12),
|
|
65
|
+
hex.substring(12, 16),
|
|
66
|
+
hex.substring(16, 20),
|
|
67
|
+
hex.substring(20, 32),
|
|
68
|
+
].join("-")
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function splitmix32(a: number) {
|
|
73
|
+
return function () {
|
|
74
|
+
a = Math.trunc(a)
|
|
75
|
+
a = Math.trunc(a + 0x9e3779b9)
|
|
76
|
+
let t = a ^ a >>> 16
|
|
77
|
+
t = Math.imul(t, 0x21f0aaad)
|
|
78
|
+
t = t ^ t >>> 15
|
|
79
|
+
t = Math.imul(t, 0x735a2d97)
|
|
80
|
+
return ((t = t ^ t >>> 15) >>> 0) / 4294967296
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { describe, it } from "node:test";
|
|
2
|
+
import Harness from "./harness"
|
|
3
|
+
import { sleepSeconds } from "./util";
|
|
4
|
+
import { Consumer, Producer } from "./kafka";
|
|
5
|
+
const ProducerLegacy = require('@mojaloop/central-services-stream').Util.Producer
|
|
6
|
+
const ConsumerLegacy = require('@mojaloop/central-services-stream').Kafka.Consumer
|
|
7
|
+
|
|
8
|
+
const harness = Harness.getInstance()
|
|
9
|
+
|
|
10
|
+
const NUM_MESSAGES = 1_000_000
|
|
11
|
+
const NUM_BATCHES = 10
|
|
12
|
+
const MESSAGES_PER_BATCH = Math.floor(NUM_MESSAGES / NUM_BATCHES)
|
|
13
|
+
|
|
14
|
+
const formatMs = (ms: number): string => {
|
|
15
|
+
return ms.toLocaleString().split('.')[0]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const formatInt = (ms: number): string => {
|
|
19
|
+
return ms.toLocaleString()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* This is a benchmark that compares the plain node-rdkafka performance to central-services-stream.
|
|
24
|
+
*/
|
|
25
|
+
describe('producer benchmark', () => {
|
|
26
|
+
it('[node-rdkafka] connects and produces poll interval', async () => {
|
|
27
|
+
await harness.up()
|
|
28
|
+
|
|
29
|
+
const broker = `localhost:${harness.redpandaConnectionOptions.port}`
|
|
30
|
+
const producer = new Producer(broker)
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
await producer.connect(err => {
|
|
34
|
+
console.error('producer error', err.message)
|
|
35
|
+
})
|
|
36
|
+
const testStart = performance.now()
|
|
37
|
+
|
|
38
|
+
console.log(`[node-rdkafka] Producing: ${formatInt(NUM_MESSAGES)} messages (pollInterval = 50ms)`)
|
|
39
|
+
|
|
40
|
+
for (let batchNum = 0; batchNum < NUM_BATCHES; batchNum++) {
|
|
41
|
+
const batchStart = performance.now()
|
|
42
|
+
let batch: Array<LegacyMessage> = []
|
|
43
|
+
for (let messageNum = 0; messageNum < MESSAGES_PER_BATCH; messageNum++) {
|
|
44
|
+
batch.push({
|
|
45
|
+
from: "lewis",
|
|
46
|
+
to: "lewis",
|
|
47
|
+
id: 0,
|
|
48
|
+
content: { "hello": true },
|
|
49
|
+
type: "",
|
|
50
|
+
metadata: undefined,
|
|
51
|
+
pp: undefined
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await producer.produce('thingo', batch)
|
|
56
|
+
const batchEnd = performance.now()
|
|
57
|
+
console.log(` - Produced: ${formatInt(MESSAGES_PER_BATCH)} messages in ${formatMs(batchEnd - batchStart)} ms`)
|
|
58
|
+
}
|
|
59
|
+
const testEnd = performance.now()
|
|
60
|
+
console.log(`[node-rdkafka] produced ${formatInt(NUM_MESSAGES)} messages across ${formatInt(NUM_BATCHES)} batches took: ${formatMs(testEnd - testStart)} ms`)
|
|
61
|
+
} finally {
|
|
62
|
+
await producer.disconnect()
|
|
63
|
+
await harness.down()
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('[central-services-stream] connects and produces', async () => {
|
|
68
|
+
await harness.up()
|
|
69
|
+
const configs = [
|
|
70
|
+
{
|
|
71
|
+
topicConfig: {
|
|
72
|
+
topicName: 'thingo',
|
|
73
|
+
},
|
|
74
|
+
kafkaConfig: {
|
|
75
|
+
options: {
|
|
76
|
+
messageCharset: "utf8"
|
|
77
|
+
},
|
|
78
|
+
topicConfig: {
|
|
79
|
+
topicName: 'thingo',
|
|
80
|
+
},
|
|
81
|
+
rdkafkaConf: {
|
|
82
|
+
"metadata.broker.list": `localhost:${harness.redpandaConnectionOptions.port}`,
|
|
83
|
+
"client.id": "test-client",
|
|
84
|
+
"event_cb": true,
|
|
85
|
+
"dr_cb": true,
|
|
86
|
+
"socket.keepalive.enable": true,
|
|
87
|
+
"queue.buffering.max.messages": 10000000
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
await ProducerLegacy.connectAll(configs)
|
|
95
|
+
const testStart = performance.now()
|
|
96
|
+
|
|
97
|
+
console.log(`[central-services-stream] Producing: ${formatInt(NUM_MESSAGES)} messages`)
|
|
98
|
+
|
|
99
|
+
for (let batchNum = 0; batchNum < NUM_BATCHES; batchNum++) {
|
|
100
|
+
const batchStart = performance.now()
|
|
101
|
+
let batch: Array<LegacyMessage> = []
|
|
102
|
+
for (let messageNum = 0; messageNum < MESSAGES_PER_BATCH; messageNum++) {
|
|
103
|
+
batch.push({
|
|
104
|
+
from: "lewis",
|
|
105
|
+
to: "lewis",
|
|
106
|
+
id: 0,
|
|
107
|
+
content: { "hello": true },
|
|
108
|
+
type: "",
|
|
109
|
+
metadata: undefined,
|
|
110
|
+
pp: undefined
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
await produceLegacyMessage('thingo', batch)
|
|
115
|
+
|
|
116
|
+
const batchEnd = performance.now()
|
|
117
|
+
console.log(` - Produced: ${formatInt(MESSAGES_PER_BATCH)} messages in ${formatMs(batchEnd - batchStart)} ms`)
|
|
118
|
+
}
|
|
119
|
+
const testEnd = performance.now()
|
|
120
|
+
console.log(`[central-services-stream] produced ${formatInt(NUM_MESSAGES)} messages across ${formatInt(NUM_BATCHES)} batches took: ${formatMs(testEnd - testStart)} ms`)
|
|
121
|
+
} finally {
|
|
122
|
+
await ProducerLegacy.disconnect()
|
|
123
|
+
await harness.down()
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
describe('consumer benchmark', () => {
|
|
129
|
+
const produceMessages = async () => {
|
|
130
|
+
const broker = `localhost:${harness.redpandaConnectionOptions.port}`
|
|
131
|
+
const producer = new Producer(broker)
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
await producer.connect(err => {
|
|
135
|
+
console.error('producer error', err.message)
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
console.log(`[setup] Producing: ${formatInt(NUM_MESSAGES)} messages.`)
|
|
139
|
+
|
|
140
|
+
for (let batchNum = 0; batchNum < NUM_BATCHES; batchNum++) {
|
|
141
|
+
let batch: Array<LegacyMessage> = []
|
|
142
|
+
for (let messageNum = 0; messageNum < MESSAGES_PER_BATCH; messageNum++) {
|
|
143
|
+
batch.push({
|
|
144
|
+
from: "lewis",
|
|
145
|
+
to: "lewis",
|
|
146
|
+
id: 0,
|
|
147
|
+
content: { "hello": true },
|
|
148
|
+
type: "",
|
|
149
|
+
metadata: undefined,
|
|
150
|
+
pp: undefined
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
await producer.produce('thingo', batch)
|
|
155
|
+
}
|
|
156
|
+
} finally {
|
|
157
|
+
await producer.disconnect()
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
it('[node-rdkafka] consumes all of the messages', async () => {
|
|
162
|
+
await harness.up()
|
|
163
|
+
await produceMessages()
|
|
164
|
+
const broker = `localhost:${harness.redpandaConnectionOptions.port}`
|
|
165
|
+
|
|
166
|
+
let countConsumed = 0
|
|
167
|
+
let remainingRetries = 10
|
|
168
|
+
const consumer = new Consumer('test-group', broker)
|
|
169
|
+
try {
|
|
170
|
+
console.log(`[node-rdkafka] consuming: ${formatInt(NUM_MESSAGES)} messages.`)
|
|
171
|
+
const consumeStart = performance.now()
|
|
172
|
+
|
|
173
|
+
await consumer.subscribe(['thingo'], (message) => {
|
|
174
|
+
countConsumed += 1
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
while (countConsumed < NUM_MESSAGES) {
|
|
178
|
+
if (remainingRetries === 0) {
|
|
179
|
+
throw new Error(`Timed out waiting to consume ${formatInt(NUM_MESSAGES)}.`)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
await sleepSeconds(1)
|
|
183
|
+
console.log(` - consumed ${formatInt(countConsumed)} took: ${formatMs(performance.now() - consumeStart)} ms`)
|
|
184
|
+
remainingRetries -= 1;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const consumeEnd = performance.now()
|
|
188
|
+
console.log(`[node-rdkafka] consumed ${formatInt(NUM_MESSAGES)} took: ${formatMs(consumeEnd - consumeStart)} ms`)
|
|
189
|
+
} finally {
|
|
190
|
+
consumer.disconnect()
|
|
191
|
+
harness.down()
|
|
192
|
+
}
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
it('[central-services-stream] consumes all of the messages', async () => {
|
|
196
|
+
await harness.up()
|
|
197
|
+
await produceMessages()
|
|
198
|
+
|
|
199
|
+
const consumerConfig = {
|
|
200
|
+
topicConf: {
|
|
201
|
+
"auto.offset.reset": 'earliest',
|
|
202
|
+
},
|
|
203
|
+
rdkafkaConf: {
|
|
204
|
+
"group.id": 'test-consumer-group',
|
|
205
|
+
"metadata.broker.list": `localhost:${harness.redpandaConnectionOptions.port}`,
|
|
206
|
+
"client.id": "test-client",
|
|
207
|
+
"socket.keepalive.enable": true,
|
|
208
|
+
"queue.buffering.max.messages": 10000000
|
|
209
|
+
},
|
|
210
|
+
}
|
|
211
|
+
const consumer = new ConsumerLegacy(['thingo'], consumerConfig)
|
|
212
|
+
let countConsumed = 0
|
|
213
|
+
let remainingRetries = 20
|
|
214
|
+
try {
|
|
215
|
+
console.log(`[central-services-stream] consuming: ${formatInt(NUM_MESSAGES)} messages.`)
|
|
216
|
+
const consumeStart = performance.now()
|
|
217
|
+
|
|
218
|
+
await consumer.connect()
|
|
219
|
+
await consumer.consume((err: any, messages: Array<any>) => {
|
|
220
|
+
countConsumed += 1
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
while (countConsumed < NUM_MESSAGES) {
|
|
224
|
+
if (remainingRetries === 0) {
|
|
225
|
+
throw new Error(`Timed out waiting to consume ${formatInt(NUM_MESSAGES)}.`)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
await sleepSeconds(1)
|
|
229
|
+
console.log(` - consumed ${formatInt(countConsumed)} took: ${formatMs(performance.now() - consumeStart)} ms`)
|
|
230
|
+
remainingRetries -= 1;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const consumeEnd = performance.now()
|
|
234
|
+
console.log(`[central-services-stream] consumed ${formatInt(NUM_MESSAGES)} took: ${formatMs(consumeEnd - consumeStart)} ms`)
|
|
235
|
+
} finally {
|
|
236
|
+
await new Promise((resolve, reject) => consumer.disconnect(resolve))
|
|
237
|
+
harness.down()
|
|
238
|
+
}
|
|
239
|
+
})
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
type LegacyMessage = {
|
|
243
|
+
from: string,
|
|
244
|
+
to: string,
|
|
245
|
+
id: number,
|
|
246
|
+
content: any,
|
|
247
|
+
type: string,
|
|
248
|
+
metadata: any,
|
|
249
|
+
pp: any
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const produceLegacyMessage = async (topic: string, messages: Array<LegacyMessage>): Promise<void> => {
|
|
253
|
+
const topicConf = {
|
|
254
|
+
topicName: topic,
|
|
255
|
+
}
|
|
256
|
+
const config = {
|
|
257
|
+
|
|
258
|
+
}
|
|
259
|
+
const promises = Promise.all(messages.map(message => {
|
|
260
|
+
return ProducerLegacy.produceMessage(message, topicConf, config)
|
|
261
|
+
}))
|
|
262
|
+
await promises
|
|
263
|
+
}
|