1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- // 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<any> {
- return new Observable((observer) => {
- prepareResponseMessages(20, 300).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: () => {
- observer.next({ header: { messageID: request.header.messageID }, complete: true })
- observer.complete()
- }
- })
- })
- }
|