test3a.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { Observable, map, Subject, takeUntil, take } from "rxjs";
  2. import { BaseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
  3. import { LogSetting } from "../dependencies/fisloggingservice/type/datatype";
  4. import { AcknowledgementService } from "../services/acknowledgement.service";
  5. import { IncomingMessageService } from "../services/incomingMessage.service";
  6. import { MessageSyncrhonizationService } from "../services/synchronization.service";
  7. import { MessageSynchronisationServiceSetting } from "../type/datatype";
  8. import { StreamingService } from "./test-streamOBS";
  9. /* Pre - Defined Data && Settings */
  10. const stream = new StreamingService()
  11. // Declare source Services && Observables (Using File Storage) Simulating Full Logs
  12. const source_synchronize = new MessageSyncrhonizationService()
  13. const source_payload: Observable<BaseMessage> = stream.stream()
  14. const source_incoming = new IncomingMessageService()
  15. const source_acknowledge = new AcknowledgementService()
  16. const source_payload_string = source_payload.pipe(
  17. map((data) => {
  18. return JSON.stringify(data);
  19. })
  20. )
  21. // Declare target Services && Observables (Using MongoDB Storage) Simlluating Partial Logs
  22. const target_payload: Observable<BaseMessage> = stream.stream().pipe(take(2))
  23. const target_payload_subject: Subject<BaseMessage> = new Subject();
  24. target_payload.subscribe(
  25. {
  26. next: (data) => {
  27. target_payload_subject.next(data)
  28. }
  29. }
  30. )
  31. const target_incoming = new IncomingMessageService()
  32. const target_syncrhonize = new MessageSyncrhonizationService()
  33. const target_acknowledge = new AcknowledgementService()
  34. const target_payload_string = target_payload.pipe(
  35. map((data) => {
  36. return JSON.stringify(data);
  37. }),
  38. )
  39. // Decalre Source Storage
  40. let source_storage: LogSetting = {
  41. storage: "File",
  42. setting: {
  43. appName: 'Default from client',
  44. appLocName: 'To be generated in client',
  45. logLocName: 'To be generated in client',
  46. }
  47. }
  48. let source_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
  49. storage: source_storage.storage,
  50. setting: source_storage.setting,
  51. customSetting: source_storage.customSetting,
  52. incomingObservable: source_payload
  53. }
  54. //Declare Target Storage
  55. let target_storage: LogSetting = {
  56. storage: "MongoDB",
  57. setting: {
  58. appName: 'Default from client',
  59. appLocName: 'To be generated in client',
  60. logLocName: 'To be generated in client',
  61. },
  62. customSetting: {
  63. srv: true,
  64. user: "testDB",
  65. password: "h1nt1OyXw6QeUnzS",
  66. server: "cluster0.29sklte.mongodb.net",
  67. collection: "log",
  68. }
  69. }
  70. let target_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
  71. storage: target_storage.storage,
  72. setting: target_storage.setting,
  73. customSetting: target_storage.customSetting,
  74. incomingObservable: target_payload
  75. }
  76. // Combine source and target storage to form MessageSynchronisationServiceSetting
  77. let settings: MessageSynchronisationServiceSetting = {
  78. incomingSource: {
  79. //all of the settings to be combined here
  80. ...source_storage,
  81. tags: ['Incoming']
  82. }, //LogSetting & {tags:string[] },
  83. target: {
  84. ...target_storage,
  85. tags: ['Incoming']
  86. } //LogSetting & {tags:string[] }
  87. }
  88. /* -------- SYNCHRONIZATION --------- */
  89. function initializeData() {
  90. source_incoming.init(source_dataSet)
  91. target_incoming.init(target_dataSet)
  92. }
  93. /* Type 1 synchronization */
  94. source_synchronize.init(settings).then(() => {
  95. source_synchronize.subscribe(source_payload_string).then((data) => {
  96. data.subscribe({
  97. next: data => {
  98. console.log(`Here's the missing data to be synchronized to target`)
  99. console.log(data.appData.msgId)
  100. target_payload_subject.next(data)
  101. }
  102. })
  103. })
  104. })
  105. // synch.subscribe({
  106. // next: (data) => {
  107. // target_payload_subject.next(data)
  108. // console.log(data)
  109. // }
  110. // })
  111. // initializeData()