test3a.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { resolve } from "path";
  2. import { Observable, map, Subject, takeUntil, take } from "rxjs";
  3. import { BaseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
  4. import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
  5. import { AcknowledgementService } from "../services/acknowledgement.service";
  6. import { IncomingMessageService } from "../services/incomingMessage.service";
  7. import { MessageSyncrhonizationService } from "../services/synchronization.service";
  8. import { MessageSynchronisationServiceSetting } from "../type/datatype";
  9. import { StreamingService } from "./test-streamOBS";
  10. /* Pre - Defined Data && Settings */
  11. const stream = new StreamingService()
  12. // Declare source Services && Observables (Using File Storage) Simulating Full Logs
  13. const source_synchronize = new MessageSyncrhonizationService()
  14. const source_payload: Observable<BaseMessage> = stream.stream().pipe()
  15. const source_incoming = new IncomingMessageService()
  16. const source_payload_subject: Subject<BaseMessage> = new Subject()
  17. source_payload.subscribe({
  18. next: (data) => {
  19. source_payload_subject.next(data)
  20. // console.log(data)
  21. }
  22. })
  23. const source_payload_string = source_payload.pipe(
  24. map((data) => {
  25. return JSON.stringify(data);
  26. })
  27. )
  28. // Declare target Services && Observables (Using MongoDB Storage) Simulating Partial Logs
  29. const target_syncrhonize = new MessageSyncrhonizationService()
  30. const target_payload: Observable<BaseMessage> = stream.stream().pipe(take(2))
  31. const target_payload_subject: Subject<BaseMessage> = new Subject()
  32. const target_incoming = new IncomingMessageService()
  33. target_payload.subscribe({
  34. next: (data) => {
  35. target_payload_subject.next(<BaseMessage>data)
  36. }
  37. })
  38. const target_payload_string = target_payload.pipe(
  39. map((data) => {
  40. return JSON.stringify(data);
  41. }),
  42. )
  43. // testing to see if data is sent in
  44. target_payload_subject.subscribe({
  45. next: element => {
  46. // console.log(element)
  47. // Missing MessageLog Data is sent in
  48. }
  49. })
  50. // Declare Source Storage
  51. let source_storage: LogSetting = {
  52. storage: "File",
  53. setting: {
  54. appName: 'Default from client',
  55. appLocName: 'To be generated in client',
  56. logLocName: 'To be generated in client',
  57. }
  58. }
  59. let source_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
  60. storage: source_storage.storage,
  61. setting: source_storage.setting,
  62. customSetting: source_storage.customSetting,
  63. incomingObservable: source_payload_subject
  64. }
  65. //Declare Target Storage
  66. let target_storage: LogSetting = {
  67. storage: "MongoDB",
  68. setting: {
  69. appName: 'Default from client',
  70. appLocName: 'To be generated in client',
  71. logLocName: 'To be generated in client',
  72. },
  73. customSetting: {
  74. srv: true,
  75. user: "testDB",
  76. password: "h1nt1OyXw6QeUnzS",
  77. server: "cluster0.29sklte.mongodb.net",
  78. collection: "log",
  79. }
  80. }
  81. let target_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
  82. storage: target_storage.storage,
  83. setting: target_storage.setting,
  84. customSetting: target_storage.customSetting,
  85. incomingObservable: target_payload_subject
  86. }
  87. // Combine source and target storage to form MessageSynchronisationServiceSetting
  88. let settings: MessageSynchronisationServiceSetting = {
  89. incomingSource: {
  90. //all of the settings to be combined here
  91. ...source_storage,
  92. tags: ['Incoming']
  93. }, //LogSetting & {tags:string[] },
  94. target: {
  95. ...target_storage,
  96. tags: ['Incoming']
  97. } //LogSetting & {tags:string[] }
  98. }
  99. /* -------- SYNCHRONIZATION --------- */
  100. function initializeData() {
  101. source_incoming.init(source_dataSet)
  102. target_incoming.init(target_dataSet)
  103. }
  104. /* Run this code to put some data into the database. 4 in File storage and 2 in Mongo */
  105. // initializeData()
  106. /* Type 1 synchronization */
  107. /* Please note that this operation assumes that there's already existing data in the designated storage place. It still cannot perform real-time live streaming dynamically
  108. when there is a streaming occuring. */
  109. // source_synchronize.init(settings).then(() => {
  110. // source_synchronize.subscribe(source_payload_string).subscribe({
  111. // next: (msgToBeSynchronized) => {
  112. // target_payload_subject.next(msgToBeSynchronized)
  113. // // console.log(msgToBeSynchronized) // It does log missing items
  114. // }
  115. // })
  116. // })
  117. source_synchronize.init(settings).then(() => {
  118. let stream = source_synchronize.subscribe(source_payload_string) // this returns an observable declared with stream
  119. stream.subscribe({
  120. next: (messageToBeSync) => {
  121. target_payload_subject.next(messageToBeSync)
  122. // console.log(messageToBeSync)
  123. }
  124. })
  125. })