|
@@ -0,0 +1,208 @@
|
|
|
+
|
|
|
+
|
|
|
+import * as mongoose from 'mongoose'
|
|
|
+import { Observable, map, Subject, takeUntil, take, of, timer, from } from "rxjs";
|
|
|
+import { ErrorTrigger, MessageSynchronisationServiceSetting } from "../type/datatype";
|
|
|
+import { StreamingService } from "./test-streamOBS";
|
|
|
+import { MessageAuditorService } from "../services/message-auditor.service";
|
|
|
+import { LoggingService } from "../dependencies/fisloggingservice/interface/export";
|
|
|
+import { BaseMessage, ResponseMessage } from "../dependencies/fisappmessagejsutilty/interface/export";
|
|
|
+import { LogSetting } from "../dependencies/fisloggingservice/type/datatype";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+const stream = new StreamingService()
|
|
|
+
|
|
|
+
|
|
|
+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 primary_sync = new MessageAuditorService()
|
|
|
+const primary_Log = new LoggingService()
|
|
|
+const primary: Subject<BaseMessage> = new Subject()
|
|
|
+primary.subscribe((e) => {
|
|
|
+ console.log(`Primary Received ${e.header.messageID}`)
|
|
|
+})
|
|
|
+
|
|
|
+
|
|
|
+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 secondary_log = new LoggingService()
|
|
|
+const secondary: Subject<BaseMessage> = new Subject()
|
|
|
+secondary.subscribe((e) => {
|
|
|
+ console.log(`Secondary Received ${e.header.messageID}`)
|
|
|
+})
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+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 publisher_storage: LogSetting = {
|
|
|
+ cacheMessageLimit: 0,
|
|
|
+ storage: "MongoDB",
|
|
|
+ setting: {
|
|
|
+ appName: 'Default from client',
|
|
|
+ appLocName: 'To be generated in client',
|
|
|
+ logLocName: 'To be generated in client',
|
|
|
+ },
|
|
|
+ customSetting: {
|
|
|
+ server: "192.168.100.59:27017",
|
|
|
+ database: "primary"
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+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 subscriber_storage: LogSetting = {
|
|
|
+ cacheMessageLimit: 0,
|
|
|
+ storage: "MongoDB",
|
|
|
+ setting: {
|
|
|
+ appName: 'Default from client',
|
|
|
+ appLocName: 'To be generated in client',
|
|
|
+ logLocName: 'To be generated in client',
|
|
|
+ },
|
|
|
+ customSetting: {
|
|
|
+ srv: true,
|
|
|
+ user: "testDB",
|
|
|
+ password: "h1nt1OyXw6QeUnzS",
|
|
|
+ server: "cluster0.29sklte.mongodb.net",
|
|
|
+ database: "secondary",
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+let settings: MessageSynchronisationServiceSetting = {
|
|
|
+ incomingSource: {
|
|
|
+
|
|
|
+ ...publisher_storage,
|
|
|
+ tags: ['Incoming']
|
|
|
+ },
|
|
|
+ target: {
|
|
|
+ ...subscriber_storage,
|
|
|
+ tags: ['Incoming']
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function initializeData() {
|
|
|
+ primary_Log.init(publisher_storage).then(() => {
|
|
|
+ primary_Log.subscribe(primary)
|
|
|
+ })
|
|
|
+ secondary_log.init(subscriber_storage).then(() => {
|
|
|
+ secondary_log.subscribe(secondary)
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+primary_sync.init(settings)
|
|
|
+
|
|
|
+
|
|
|
+mechanism to execute the synchronization. */
|
|
|
+let errorSubject: Subject<ErrorTrigger> = new Subject()
|
|
|
+
|
|
|
+let sync = primary_sync.subscribe(errorSubject)
|
|
|
+sync.subscribe({
|
|
|
+ next: (msgToBeSynchronized) => {
|
|
|
+ console.log(`passing missing message: ${msgToBeSynchronized.header.messageID} into target/secondary subject.`)
|
|
|
+
|
|
|
+ secondary.next(msgToBeSynchronized)
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+setTimeout(() => {
|
|
|
+
|
|
|
+
|
|
|
+ let sampleError: ErrorTrigger = {
|
|
|
+ status: 1,
|
|
|
+ message: "NO. I dont want to work"
|
|
|
+ }
|
|
|
+ errorSubject.next(sampleError)
|
|
|
+}, 10000)
|
|
|
+
|
|
|
+
|
|
|
+to act as additional trigger to exectute the synchronization when there's no internet
|
|
|
+connection. */
|
|
|
+const dns = require('dns');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function checkInternetConnectivity() {
|
|
|
+ dns.lookup('example.com', (err) => {
|
|
|
+ if (err && err.code === 'ENOTFOUND') {
|
|
|
+ let errorMsg: ErrorTrigger = {
|
|
|
+ status: 0,
|
|
|
+ message: `No internet connection`
|
|
|
+ }
|
|
|
+ errorSubject.next(errorMsg)
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+const intervalTime = 1000;
|
|
|
+
|
|
|
+
|
|
|
+const interval = setInterval(checkInternetConnectivity, intervalTime);
|
|
|
+
|
|
|
+
|
|
|
+const duration = 60000;
|
|
|
+setTimeout(function () {
|
|
|
+ clearInterval(interval);
|
|
|
+ console.log('Internet connectivity monitoring stopped');
|
|
|
+}, duration);
|
|
|
+
|
|
|
+function countdown() {
|
|
|
+ let seconds = 0;
|
|
|
+ const countUpInterval = setInterval(() => {
|
|
|
+ console.log(`Elapsed seconds: ${seconds}`);
|
|
|
+ seconds++;
|
|
|
+ }, 1000);
|
|
|
+}
|
|
|
+
|
|
|
+countdown()
|
|
|
+
|
|
|
+
|
|
|
+const Schema = mongoose.Schema;
|
|
|
+const fingerPrintSchema = new Schema({
|
|
|
+ uuid: { type: String, required: true, lowercase: true, unique: true },
|
|
|
+ fileName: { type: String, required: true, lowercase: true },
|
|
|
+ fileType: { type: String, required: true, lowercase: true },
|
|
|
+ entityName: { type: String, required: true, lowercase: true },
|
|
|
+ fileData: { type: Object, required: true },
|
|
|
+});
|
|
|
+
|
|
|
+function convertDataInMongo(url: string) {
|
|
|
+ let data: Subject<any> = new Subject()
|
|
|
+ let convertService = new LoggingService()
|
|
|
+
|
|
|
+ let dbConnection = mongoose.createConnection(url)
|
|
|
+ let dataModel = dbConnection.model('genericdata', fingerPrintSchema)
|
|
|
+ dataModel.find().then((res) => {
|
|
|
+
|
|
|
+ res.forEach((element) => {
|
|
|
+ data.next(element)
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ data.subscribe((element) => {
|
|
|
+ convertService.
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+convertDataInMongo('mongodb+srv://testDB:h1nt1OyXw6QeUnzS@cluster0.29sklte.mongodb.net/test')
|
|
|
+convertDataInMongo('mongodb://192.168.100.59:27017/hq')
|