Skip to content

Commit

Permalink
switchMap changed to flatMap, Observable resubscribed on an Error (#29)
Browse files Browse the repository at this point in the history
* switchMap changed to flatMap, Observable resubscribed on an Error

* version bumped up
  • Loading branch information
vgenev authored and deonbotha committed Apr 11, 2019
1 parent f9e4628 commit 3b6d5f0
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 62 deletions.
29 changes: 8 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "central-event-processor",
"version": "5.3.0",
"version": "5.5.0",
"description": "CEP for Mojaloop Central-Ledger to monitor the notificaion kafka topic and act on it.",
"main": "app.js",
"dependencies": {
Expand Down
169 changes: 141 additions & 28 deletions settlementSubmitter.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,140 @@
const Utility = require('./src/lib/utility')

let message = {
'id': '86ce97cf-2302-4d64-8b0e-df5ae9355dd0',
'from': 'central-switch',
'to': 'dfsp2',
'content': {
'headers': {
'Content-Type': 'application/json',
'Date': '2019-01-17T14:46:48.918Z',
'FSPIOP-Source': 'central-switch',
'FSPIOP-Destination': 'dfsp2'
let messages = [
{
'id': '86ce97cf-2302-4d64-8b0e-df5ae9355dd0',
'from': 'central-switch',
'to': 'dfsp2',
'content': {
'headers': {
'Content-Type': 'application/json',
'Date': '2019-01-17T14:46:48.918Z',
'FSPIOP-Source': 'central-switch',
'FSPIOP-Destination': 'dfsp2'
},
'payload': {
'currency': 'USD',
'value': 0,
'changedDate': '2019-01-17T14:46:48.918Z'
}
},
'type': 'application/json',
'metadata': {
'event': {
'id': '5c7ff308-35be-46b0-b187-0bf4bee72cf8',
'type': 'notification',
'action': 'settlement-transfer-position-change',
'state': {
'status': 'success',
'code': 0,
'description': 'action successful'
}
},
'protocol.createdAt': 1547736408918
}
},
{
'id': '86ce97cf-2302-4d64-8b0e-df5ae9355dd0',
'from': 'central-switch',
'to': 'dfsp1',
'content': {
'headers': {
'Content-Type': 'application/json',
'Date': '2019-01-17T14:46:48.918Z',
'FSPIOP-Source': 'central-switch',
'FSPIOP-Destination': 'dfsp2'
},
'payload': {
'currency': 'USD',
'value': 0,
'changedDate': '2019-01-17T14:46:48.918Z'
}
},
'type': 'application/json',
'metadata': {
'event': {
'id': '5c7ff308-35be-46b0-b187-0bf4bee72cf8',
'type': 'notification',
'action': 'settlement-transfer-position-change',
'state': {
'status': 'success',
'code': 0,
'description': 'action successful'
}
},
'protocol.createdAt': 1547736408918
}
},
{
'id': '86ce97cf-2302-4d64-8b0e-df5ae9355dd0',
'from': 'central-switch',
'to': 'dfsp11',
'content': {
'headers': {
'Content-Type': 'application/json',
'Date': '2019-01-17T14:46:48.918Z',
'FSPIOP-Source': 'central-switch',
'FSPIOP-Destination': 'dfsp2'
},
'payload': {
'currency': 'USD',
'value': 0,
'changedDate': '2019-01-17T14:46:48.918Z'
}
},
'payload': {
'currency': 'USD',
'value': 0,
'changedDate': '2019-01-17T14:46:48.918Z'
'type': 'application/json',
'metadata': {
'event': {
'id': '5c7ff308-35be-46b0-b187-0bf4bee72cf8',
'type': 'notification',
'action': 'settlement-transfer-position-change',
'state': {
'status': 'success',
'code': 0,
'description': 'action successful'
}
},
'protocol.createdAt': 1547736408918
}
},
'type': 'application/json',
'metadata': {
'event': {
'id': '5c7ff308-35be-46b0-b187-0bf4bee72cf8',
'type': 'notification',
'action': 'settlement-transfer-position-change',
'state': {
'status': 'success',
'code': 0,
'description': 'action successful'
{
'id': '86ce97cf-2302-4d64-8b0e-df5ae9355dd0',
'from': 'central-switch',
'to': 'dfsp12',
'content': {
'headers': {
'Content-Type': 'application/json',
'Date': '2019-01-17T14:46:48.918Z',
'FSPIOP-Source': 'central-switch',
'FSPIOP-Destination': 'dfsp2'
},
'payload': {
'currency': 'USD',
'value': 0,
'changedDate': '2019-01-17T14:46:48.918Z'
}
},
'protocol.createdAt': 1547736408918
'type': 'application/json',
'metadata': {
'event': {
'id': '5c7ff308-35be-46b0-b187-0bf4bee72cf8',
'type': 'notification',
'action': 'settlement-transfer-position-change',
'state': {
'status': 'success',
'code': 0,
'description': 'action successful'
}
},
'protocol.createdAt': 1547736408918
}
}
}

]

let count = 0

const timeout = ms => new Promise(res => setTimeout(res, ms))

let messageSubimtter = async (message) => {
try {
Expand All @@ -41,10 +144,20 @@ let messageSubimtter = async (message) => {
description: 'action successful'
}
await Utility.produceGeneralMessage('notification', 'settlement-transfer-position-change', message, success)
console.log('Message on kafka queue')
console.log('Message on kafka queue # ', ++count)
} catch (err) {
console.log('Message wasnt placed on Kaka queue : ' + err)
}
}

messageSubimtter(message)
let flood = async (count) => {
let arr = []
for (let i = 0; i < count; i++) {
for (let message of messages) {
// await timeout(100)
await messageSubimtter(message)
}
}
}

flood(20)
22 changes: 22 additions & 0 deletions src/rxretries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const Rx = require('rxjs')
const { filter, flatMap, retry, delay, retryWhen, repeat, repeatWhen, catchError } = require('rxjs/operators')

let arrO = Rx.from([1, 2, 3, 4, 5, 6, 7])

const mapped = arrO.pipe(
flatMap(v => {
return Rx.from([2 * v])
}),
delay(1000),
flatMap(v => {
if (v === 8) return Rx.throwError('error')
else return Rx.from([v])
}),
catchError(e => {
return Rx.of(undefined)
})
)

mapped.subscribe({
next: v => console.log(v)
})
Loading

0 comments on commit 3b6d5f0

Please sign in to comment.