Enzo 11 bulan lalu
induk
melakukan
6fc2d6d868
4 mengubah file dengan 7 tambahan dan 36 penghapusan
  1. 4 33
      services/buffer.service.ts
  2. 1 1
      startgrpc.bat
  3. 1 1
      startgrpc2.bat
  4. 1 1
      test/grpc1.ts

+ 4 - 33
services/buffer.service.ts

@@ -67,19 +67,7 @@ export class BufferService {
             this.bufferMessage(message);
         }
         if (this.connectionState.getValue().status === 'DIRECT_PUBLISH') {
-            // console.log(`There is ${this.messageBuffer.length} messages in the buffer`) // somehw this is called repeatedly
-            // do nothing for now
-            // Start releasing buffered messages, but don't wait for it to complete
-            // this.isBufferNotEmpty().then(isNotEmpty => {
-            //     if (isNotEmpty) {
-            //         // this.releaseBufferedMessages(this.messageFromBuffer);
-            //         // Continue to buffer new incoming message during the release process
-            //         this.bufferMessage(message);
-            //     } else {
-            //         // If buffer is empty, switch source and handle the message directly
-            //         this.messageToBePublished.next(message); // Handle the message directly
-            //     }
-            // });
+            // additional logic here
         }
     }
 
@@ -92,25 +80,6 @@ export class BufferService {
         }
         if (state.status === 'DIRECT_PUBLISH') {
             this.releaseBufferedMessages(this.messageStream)
-            /* This is for mongo  */
-            // this.isBufferNotEmpty().then(isNotEmpty => {
-            //     if (isNotEmpty) {
-            //         this.currentMessageSource = this.messageFromBuffer
-            //     } else {
-            //         this.currentMessageSource = this.messageToBePublished
-            //     }
-            // })
-        }
-    }
-
-    private async isBufferNotEmpty(): Promise<boolean> {
-        if (this.messageModel) {
-            // Check the count in MongoDB
-            const count = await this.messageModel.estimatedDocumentCount().exec();
-            return count > 0;
-        } else {
-            // Check the local buffer
-            return this.messageBuffer.length > 0;
         }
     }
 
@@ -119,7 +88,9 @@ export class BufferService {
             try {
                 // const newMessage = new this.messageModel(message);
                 await this.messageModel.create(message);
-                console.log(`Message${(message.message as MessageLog).appData.msgId} saved to MongoDB buffer`);
+                this.messageModel.countDocuments({}).then((count) => {
+                    console.log(`Message${(message.message as MessageLog).appData.msgId} saved to MongoDB buffer. There is ${count} messages in datatbase at the moment.`);
+                })
             } catch (error) {
                 console.error('Error saving message to MongoDB:', error);
                 // Implement retry logic or additional error handling here

+ 1 - 1
startgrpc.bat

@@ -1,6 +1,6 @@
 
 @echo off
-start wt -M -d "C:\Users\esenz\dev\Task\Fis-Restransmission" cmd /k "npm run grpc1" ; split-pane -d "C:\Users\esenz\dev\Task\Fis-Restransmission" cmd /k "npm run grpc2" ; split-pane -d "C:\Users\esenz\dev\Task\Fis-Restransmission" cmd /k "npm run grpc3"
+start wt -M -d "E:\Task\Fis-Restransmission" cmd /k "npm run grpc1" ; split-pane -d "E:\Task\Fis-Restransmission" cmd /k "npm run grpc2" ; split-pane -d "E:\Task\Fis-Restransmission" cmd /k "npm run grpc3"
 
 
 //wt -p "Command Prompt" ; split-pane -p "Windows PowerShell" ; split-pane -H 

+ 1 - 1
startgrpc2.bat

@@ -1,6 +1,6 @@
 
 @echo off
-start wt -M -d "C:\Users\esenz\dev\Task\Fis-Restransmission" cmd /k "npm run grpc1" ; split-pane -d "C:\Users\esenz\dev\Task\Fis-Restransmission" cmd /k "npm run grpc2"
+start wt -M -d "E:\Task\Fis-Restransmission" cmd /k "npm run grpc1" ; split-pane -d "E:\Task\Fis-Restransmission" cmd /k "npm run grpc2"
 
 
 //wt -p "Command Prompt" ; split-pane -p "Windows PowerShell" ; split-pane -H 

+ 1 - 1
test/grpc1.ts

@@ -316,7 +316,7 @@ function stream(): Subject<any> {
   const intervalId = setInterval(() => {
     result.next(messages[count]);
     count++;
-    if (count >= 3000) {
+    if (count >= 2000) {
       clearInterval(intervalId);
       result.complete();
     }