|
@@ -8,11 +8,11 @@ import { ServerClientManager } from '../services/server-client.service';
|
|
|
const connectionService: ServerClientManager = new ServerClientManager(new GrpcServiceMethod())
|
|
|
const messagesJSON: any = readFileSync('payload.json')
|
|
|
let parsedMessages: any[] = JSON.parse(messagesJSON) // load the fake messages generated for this trial
|
|
|
-let targetserver: string = 'localhost:300'
|
|
|
-// let targetserver2: string = 'localhost:3002'
|
|
|
+let targetserver: string = 'localhost:3001'
|
|
|
+let targetserver2: string = 'localhost:3002'
|
|
|
let hostServer: string = 'localhost:3002'
|
|
|
let array: any[] = [] // Used for testing
|
|
|
-let request: ConnectionRequest = {
|
|
|
+let connectionRequest: ConnectionRequest = {
|
|
|
server: {
|
|
|
serverUrl: hostServer,
|
|
|
connectionType: 'GRPC',
|
|
@@ -22,22 +22,22 @@ let request: ConnectionRequest = {
|
|
|
targetServer: targetserver,
|
|
|
connectionType: 'GRPC',
|
|
|
messageToBeReceivedFromRemote: new Subject<Message>()
|
|
|
- },
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Handler for the incoming Messages from the other side.
|
|
|
-request.client.messageToBeReceivedFromRemote.subscribe({
|
|
|
+connectionRequest.client.messageToBeReceivedFromRemote.subscribe({
|
|
|
next: request => {
|
|
|
// Application logic comes here. This is where the asortment takes place, of decidiing whose messages it belongs of what it is
|
|
|
if ((request.message as MessageLog).appData.msgPayload == 'Query') {
|
|
|
generateFakeStreamResponse(request).subscribe({
|
|
|
- next: (responseMessage) => {
|
|
|
+ next: (responseMessage: Message) => {
|
|
|
// console.log(`Processing request:${request.id}....`)
|
|
|
- request.server.messageToBePublishedfromApplication.next(responseMessage)
|
|
|
+ connectionRequest.server.messageToBePublishedfromApplication.next(responseMessage)
|
|
|
},
|
|
|
error: error => console.error(error),
|
|
|
complete: () => {
|
|
|
- console.log(`Stream request for ${request.id} is queued.`) // should be indefinite
|
|
|
+ console.log(`Stream request for ${request.id} is queued.`) // shpuld be indefinite
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
@@ -51,24 +51,35 @@ request.client.messageToBeReceivedFromRemote.subscribe({
|
|
|
|
|
|
|
|
|
|
|
|
-connectionService.generateConnection(request)
|
|
|
-// grpcService.createGrpcInstance(hostServer, { instanceType: 'server', serviceMethod: 'server streaming' }, messageToBeReleased)
|
|
|
+connectionService.generateConnection(connectionRequest)
|
|
|
+
|
|
|
+/* Simple Test */
|
|
|
+// let generateFakeMessagesToBePublished = stream().pipe(take(10))
|
|
|
+// generateFakeMessagesToBePublished.subscribe({
|
|
|
+// next: message => {
|
|
|
+// let payload: Message = {
|
|
|
+// id: hostServer,
|
|
|
+// message: JSON.stringify(message)
|
|
|
+// }
|
|
|
+// connectionRequest.server.messageToBePublishedfromApplication.next(payload)
|
|
|
+// }
|
|
|
+// })
|
|
|
|
|
|
-// grpcService.createGrpcInstance(targetserver, { instanceType: 'client', serviceMethod: 'server streaming' })
|
|
|
|
|
|
+/* Complex Test */
|
|
|
// setTimeout(() => {
|
|
|
// let message = {
|
|
|
// id: parsedMessages[10].appData.msgId,
|
|
|
// message: parsedMessages[10] // Choose this number, because i purposely use the 11th message and change the msgPayload property to query to emulate a request
|
|
|
// }
|
|
|
-// applicationOutgoingResponse.next(message)
|
|
|
+// connectionRequest.server.messageToBePublishedfromApplication.next(message)
|
|
|
// }, 3000)
|
|
|
// setTimeout(() => {
|
|
|
// let message = {
|
|
|
// id: parsedMessages[11].appData.msgId,
|
|
|
// message: parsedMessages[11]// Choose this number, because i purposely use the 11th message and change the msgPayload property to query to emulate a request
|
|
|
// }
|
|
|
-// applicationOutgoingResponse.next(message)
|
|
|
+// connectionRequest.server.messageToBePublishedfromApplication.next(message)
|
|
|
// }, 4000)
|
|
|
// setTimeout(() => {
|
|
|
// console.log(`All received data: ${array.length}`)
|