prepareFISmessage.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { interval, Observable, Subject, Subscription } from "rxjs"
  2. import { FisCreateMessageUtility } from "../../dependencies/logging/dependencies/msgutil/services/fis.create.message"
  3. import { BaseMessage } from "../../dependencies/logging/services/logging-service"
  4. let messageUtil: FisCreateMessageUtility = new FisCreateMessageUtility("FisAppID/Name")
  5. export function prepareResponseMessages(amount: number, intervalBetweenMessages?: number): Subject<BaseMessage> {
  6. let responseData: any[] = []
  7. let returnSubject = new Subject<BaseMessage>()
  8. for (let i = 0; i < 1000; i++) {
  9. responseData.push(`bla bla bla`)
  10. }
  11. let count = 0
  12. let subscription: Subscription
  13. if (intervalBetweenMessages) {
  14. // console.log(`Generate data with intervals`)
  15. subscription = interval(intervalBetweenMessages).subscribe({ // 10millisecond
  16. next: () => {
  17. count++
  18. if (count <= amount) {
  19. let message = messageUtil.getResponseDataMessage('123', responseData, messageUtil.getLoginMessage())
  20. returnSubject.next(message)
  21. } else {
  22. returnSubject.complete()
  23. subscription.unsubscribe()
  24. }
  25. }
  26. });
  27. } else {
  28. // console.log(`Generate data without intervals`)
  29. for (let i = 0; i <= amount; i++) {
  30. if (i >= amount) {
  31. returnSubject.complete()
  32. } else {
  33. let message = messageUtil.getResponseDataMessage('123', responseData, messageUtil.getLoginMessage())
  34. returnSubject.next(message)
  35. }
  36. }
  37. }
  38. return returnSubject
  39. }
  40. export function generateSingleMessage() {
  41. return messageUtil.getResponseDataMessage('123', [], messageUtil.getLoginMessage())
  42. }