|
@@ -6,30 +6,36 @@ server data, and then synchronizing them */
|
|
import { Observable, map, Subject, takeUntil, take, of, timer, from } from "rxjs";
|
|
import { Observable, map, Subject, takeUntil, take, of, timer, from } from "rxjs";
|
|
import { BaseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
|
|
import { BaseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
|
|
import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
|
|
import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
|
|
-import { AcknowledgementService } from "../services/acknowledgement.service";
|
|
|
|
import { IncomingMessageService } from "../services/incomingMessage.service";
|
|
import { IncomingMessageService } from "../services/incomingMessage.service";
|
|
import { MessageSyncrhonizationService } from "../services/synchronization.service";
|
|
import { MessageSyncrhonizationService } from "../services/synchronization.service";
|
|
-import { MessageSynchronisationServiceSetting } from "../type/datatype";
|
|
|
|
|
|
+import { ErrorTrigger, MessageSynchronisationServiceSetting } from "../type/datatype";
|
|
import { StreamingService } from "./test-streamOBS";
|
|
import { StreamingService } from "./test-streamOBS";
|
|
|
|
|
|
/* Pre - Defined Data && Settings */
|
|
/* Pre - Defined Data && Settings */
|
|
|
|
+// This service will stream the messages from the local testRequest.json messages
|
|
|
|
+// into the designated location that will be specified later.
|
|
const stream = new StreamingService()
|
|
const stream = new StreamingService()
|
|
|
|
|
|
-// Declare source Services && Observables (Using File Storage) Simulating Full Logs
|
|
|
|
|
|
+/* Using the instance of the streaming declared earlier, we feed 4 messages into the
|
|
|
|
+subscribers that are going to subsscribe to this source_payload. Please note that
|
|
|
|
+source_payload will emite the messages stream from the instance of stream service
|
|
|
|
+and further feed them into the other Subject which is called source_payload_subject. */
|
|
const source_synchronize = new MessageSyncrhonizationService()
|
|
const source_synchronize = new MessageSyncrhonizationService()
|
|
-const source_payload: Observable<BaseMessage> = stream.stream().pipe(take(4))
|
|
|
|
const source_incoming = new IncomingMessageService()
|
|
const source_incoming = new IncomingMessageService()
|
|
|
|
+const source_payload: Observable<BaseMessage> = stream.stream().pipe(take(4))
|
|
const source_payload_subject: Subject<BaseMessage> = new Subject()
|
|
const source_payload_subject: Subject<BaseMessage> = new Subject()
|
|
source_payload.subscribe({
|
|
source_payload.subscribe({
|
|
next: (data) => {
|
|
next: (data) => {
|
|
source_payload_subject.next(data)
|
|
source_payload_subject.next(data)
|
|
- // console.log(data)
|
|
|
|
}
|
|
}
|
|
})
|
|
})
|
|
-// Declare target Services && Observables (Using MongoDB Storage) Simulating Partial Logs
|
|
|
|
|
|
+
|
|
|
|
+/* Same thing as the above. The only difference is the we feed only 2 messages
|
|
|
|
+to simulate streaming error. We want to see if it will sync the other 2 later
|
|
|
|
+on. But generall the declarative structure is the same as the above. */
|
|
|
|
+const target_incoming = new IncomingMessageService()
|
|
const target_payload: Observable<BaseMessage> = stream.stream().pipe(take(2))
|
|
const target_payload: Observable<BaseMessage> = stream.stream().pipe(take(2))
|
|
const target_payload_subject: Subject<BaseMessage> = new Subject()
|
|
const target_payload_subject: Subject<BaseMessage> = new Subject()
|
|
-const target_incoming = new IncomingMessageService()
|
|
|
|
target_payload.subscribe({
|
|
target_payload.subscribe({
|
|
next: (data) => {
|
|
next: (data) => {
|
|
target_payload_subject.next(<BaseMessage>data)
|
|
target_payload_subject.next(<BaseMessage>data)
|
|
@@ -38,15 +44,13 @@ target_payload.subscribe({
|
|
complete: () => { `Target Payload Completed` }
|
|
complete: () => { `Target Payload Completed` }
|
|
})
|
|
})
|
|
|
|
|
|
-// testing to see if data is sent in
|
|
|
|
-target_payload_subject.subscribe({
|
|
|
|
- next: element => {
|
|
|
|
- console.log(`target_payload_subject emits :00 ${element.header.messageID}`)
|
|
|
|
- }
|
|
|
|
-})
|
|
|
|
|
|
|
|
-// Declare Source Storage
|
|
|
|
|
|
+/* Declare the designated database. I am using windev's mongo storage to store the data.
|
|
|
|
+Hence here, is the block that definte the target and it's associated specifications.
|
|
|
|
+This will be the target and will receive the predefined set of data to be logged as
|
|
|
|
+prepared earlier in the code above.s */
|
|
let source_storage: LogSetting = {
|
|
let source_storage: LogSetting = {
|
|
|
|
+ cacheMessageLimit: 0,
|
|
storage: "MongoDB",
|
|
storage: "MongoDB",
|
|
setting: {
|
|
setting: {
|
|
appName: 'Default from client',
|
|
appName: 'Default from client',
|
|
@@ -54,11 +58,12 @@ let source_storage: LogSetting = {
|
|
logLocName: 'To be generated in client',
|
|
logLocName: 'To be generated in client',
|
|
},
|
|
},
|
|
customSetting: {
|
|
customSetting: {
|
|
- server: "localhost:27017",
|
|
|
|
- collection: "log"
|
|
|
|
|
|
+ server: "192.168.100.59:27017",
|
|
|
|
+ database: "test"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// I forgot what this is for lol...
|
|
let source_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
|
|
let source_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
|
|
storage: source_storage.storage,
|
|
storage: source_storage.storage,
|
|
setting: source_storage.setting,
|
|
setting: source_storage.setting,
|
|
@@ -66,8 +71,12 @@ let source_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> }
|
|
incomingObservable: source_payload_subject
|
|
incomingObservable: source_payload_subject
|
|
}
|
|
}
|
|
|
|
|
|
-//Declare Target Storage
|
|
|
|
|
|
+/* Same as above. Also declaring another designated database. But this one will be used
|
|
|
|
+as the target for synching. For such I purposely push only half the of the completed
|
|
|
|
+dataset in order to test out the sync later. I am using my own cloud atlas mongo
|
|
|
|
+database on this. The address can always be changed. */
|
|
let target_storage: LogSetting = {
|
|
let target_storage: LogSetting = {
|
|
|
|
+ cacheMessageLimit: 0,
|
|
storage: "MongoDB",
|
|
storage: "MongoDB",
|
|
setting: {
|
|
setting: {
|
|
appName: 'Default from client',
|
|
appName: 'Default from client',
|
|
@@ -79,7 +88,7 @@ let target_storage: LogSetting = {
|
|
user: "testDB",
|
|
user: "testDB",
|
|
password: "h1nt1OyXw6QeUnzS",
|
|
password: "h1nt1OyXw6QeUnzS",
|
|
server: "cluster0.29sklte.mongodb.net",
|
|
server: "cluster0.29sklte.mongodb.net",
|
|
- collection: "log",
|
|
|
|
|
|
+ database: "log",
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -104,27 +113,42 @@ let settings: MessageSynchronisationServiceSetting = {
|
|
}
|
|
}
|
|
|
|
|
|
/* -------- SYNCHRONIZATION --------- */
|
|
/* -------- SYNCHRONIZATION --------- */
|
|
-function initializeData() {
|
|
|
|
|
|
+// This is where the real test begin. THe process before this were merely just configuring
|
|
|
|
+// the settings of where to sync. Here the initial intialize data will first log the
|
|
|
|
+// messages into the designated database as specified earlier.
|
|
|
|
+function initializeData() { // To store the data into the designated databases.
|
|
source_incoming.init(source_dataSet)
|
|
source_incoming.init(source_dataSet)
|
|
target_incoming.init(target_dataSet)
|
|
target_incoming.init(target_dataSet)
|
|
}
|
|
}
|
|
|
|
|
|
// Done by appoximately 5-8 Seconds
|
|
// Done by appoximately 5-8 Seconds
|
|
-initializeData()
|
|
|
|
|
|
+initializeData() // Call the function to store the data into the designated databases.
|
|
source_synchronize.init(settings)
|
|
source_synchronize.init(settings)
|
|
|
|
|
|
-// by 10th second
|
|
|
|
|
|
+/* This is where the synchronizatin happens. Upon initializin ghe target earlier, we
|
|
|
|
+will put in a trigger to execute the synching. It will check for missing datas and
|
|
|
|
+publish the missing messages accordingly. For this test purpose, we purposely set to
|
|
|
|
+7 seconds to allow the logging process earlier to take place first before engaging
|
|
|
|
+in synching activity to prevent confusion and interference of the pre-logging stage. */
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
|
|
|
- let triggerSync = from(['Newsynch'])
|
|
|
|
|
|
+ // This wil act as the trigger error. Although the definition of this error is
|
|
|
|
+ // still subject for enhancements in the near future.
|
|
|
|
+ let sampleError: ErrorTrigger = {
|
|
|
|
+ status: 1,
|
|
|
|
+ message: "NO. I dont want to work"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let triggerSync: Observable<ErrorTrigger> = from([sampleError])
|
|
|
|
|
|
let sync = source_synchronize.subscribe(triggerSync)
|
|
let sync = source_synchronize.subscribe(triggerSync)
|
|
sync.subscribe({
|
|
sync.subscribe({
|
|
next: (msgToBeSynched) => {
|
|
next: (msgToBeSynched) => {
|
|
- // console.log(`synching ... ${msgToBeSynched.header.messageID}`)
|
|
|
|
|
|
+ console.log(`synching ... ${msgToBeSynched.header.messageID}`)
|
|
target_payload_subject.next(msgToBeSynched)
|
|
target_payload_subject.next(msgToBeSynched)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
-}, 7000)
|
|
|
|
|
|
+}, 5000)
|
|
|
|
+
|
|
|
|
|