test3a.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_incoming = new IncomingMessageService()
  24. const target_syncrhonize = new MessageSyncrhonizationService()
  25. const target_acknowledge = new AcknowledgementService()
  26. const target_payload_string = target_payload.pipe(
  27. map((data) => {
  28. return JSON.stringify(data);
  29. }),
  30. )
  31. // Decalre Source Storage
  32. let source_storage: LogSetting = {
  33. storage: "File",
  34. setting: {
  35. appName: 'Default from client',
  36. appLocName: 'To be generated in client',
  37. logLocName: 'To be generated in client',
  38. }
  39. }
  40. let source_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
  41. storage: source_storage.storage,
  42. setting: source_storage.setting,
  43. customSetting: source_storage.customSetting,
  44. incomingObservable: source_payload
  45. }
  46. //Declare Target Storage
  47. let target_storage: LogSetting = {
  48. storage: "MongoDB",
  49. setting: {
  50. appName: 'Default from client',
  51. appLocName: 'To be generated in client',
  52. logLocName: 'To be generated in client',
  53. },
  54. customSetting: {
  55. srv: true,
  56. user: "testDB",
  57. password: "h1nt1OyXw6QeUnzS",
  58. server: "cluster0.29sklte.mongodb.net",
  59. collection: "log",
  60. }
  61. }
  62. let target_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
  63. storage: target_storage.storage,
  64. setting: target_storage.setting,
  65. customSetting: target_storage.customSetting,
  66. incomingObservable: target_payload
  67. }
  68. // Combine source and target storage to form MessageSynchronisationServiceSetting
  69. let settings: MessageSynchronisationServiceSetting = {
  70. incomingSource: {
  71. //all of the settings to be combined here
  72. ...source_storage,
  73. tags: ['Incoming']
  74. }, //LogSetting & {tags:string[] },
  75. target: {
  76. ...target_storage,
  77. tags: ['Incoming']
  78. } //LogSetting & {tags:string[] }
  79. }
  80. /* -------- SYNCHRONIZATION --------- */
  81. source_incoming.init(source_dataSet)
  82. target_incoming.init(target_dataSet)
  83. /* Type 1 synchronization */
  84. source_synchronize.init(settings).then(() => {
  85. source_synchronize.subscribe(source_payload_string)
  86. })
  87. // let sychnedObs = source_synchronize.subscribe(source_payload_string)
  88. // sychnedObs.subscribe(
  89. // {
  90. // next: (data) => {
  91. // target_payload.next(data)
  92. // }
  93. // }
  94. // )