1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- // 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<BaseMessage>()
- let outGoingResponses = new Subject<BaseMessage>()
- 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<BaseMessage> {
- return new Observable((observer) => {
- prepareResponseMessages(30, 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()
- }
- })
- }
- })
- })
- }
|