// so This is just for demonstaratin purpose. /* App logic will accept a request and return responses via subjects. Whether or not whose request it belongs to, would be presumed to be handled by the service */ import { Observable, Subject } from "rxjs"; import { SocketService } from "./socket.service"; import { BaseMessage } from "../../dependencies/logging/services/logging-service"; import { prepareResponseMessages } from "../../services/utility/prepareFISmessage"; let incomingRequest = new Observable() let outGoingResponses = new Subject() let socketService = new SocketService(outGoingResponses) incomingRequest = socketService.getIncomingRequest() socketService.setUpConnection() incomingRequest.subscribe((request: BaseMessage) => { returnResponse(request).subscribe({ next: message => { outGoingResponses.next(message) }, error: err => console.error(err), complete: () => { // no need to do anything console.log(`Application completed in providing responses for request${request.header.messageID}...`) } }) }) function returnResponse(request: BaseMessage): Observable { return new Observable((observer) => { prepareResponseMessages(10, 1000).subscribe({ next: (message: BaseMessage) => { message.header.messageID = request.header.messageID console.log(`Generating response message for ${request.header.messageID}`) observer.next(message) }, error: err => console.error(err), complete: () => { prepareResponseMessages(1, 1000).subscribe({ next: message => { console.log(`Finalizing complete response for request${request.header.messageID}`) message.header.messageID = request.header.messageID message.header.messageName = 'Complete' observer.next(message) }, complete: () => { observer.complete() } }) } }) }) }