123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- // 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(10, 1000).subscribe({
- next: (message: BaseMessage) => {
- message.header.messageID = request.header.messageID
- observer.next(message)
- },
- error: err => console.error(err),
- complete: () => {
- prepareResponseMessages(1, 1000).subscribe({
- next: message => {
- message.header.messageID = request.header.messageID
- message.header.messageName = 'Complete'
- observer.next(message)
- },
- complete: () => {
- observer.complete()
- }
- })
- }
- })
- })
- }
|