Replace GRPC call to geography with AMQP RPC
This commit is contained in:
parent
579415c300
commit
1fd15430a1
|
@ -19,3 +19,4 @@ export const AD_CONFIGURATION_REPOSITORY = Symbol(
|
||||||
'AD_CONFIGURATION_REPOSITORY',
|
'AD_CONFIGURATION_REPOSITORY',
|
||||||
);
|
);
|
||||||
export const GEOGRAPHY_PACKAGE = Symbol('GEOGRAPHY_PACKAGE');
|
export const GEOGRAPHY_PACKAGE = Symbol('GEOGRAPHY_PACKAGE');
|
||||||
|
export const GEOGRAPHY_SERVICE = Symbol('GEOGRAPHY_SERVICE');
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
MATCHING_REPOSITORY,
|
MATCHING_REPOSITORY,
|
||||||
AD_CONFIGURATION_REPOSITORY,
|
AD_CONFIGURATION_REPOSITORY,
|
||||||
GEOGRAPHY_PACKAGE,
|
GEOGRAPHY_PACKAGE,
|
||||||
|
GEOGRAPHY_SERVICE,
|
||||||
} from './ad.di-tokens';
|
} from './ad.di-tokens';
|
||||||
import { MessageBrokerPublisher } from '@mobicoop/message-broker-module';
|
import { MessageBrokerPublisher } from '@mobicoop/message-broker-module';
|
||||||
import { AdRepository } from './infrastructure/ad.repository';
|
import { AdRepository } from './infrastructure/ad.repository';
|
||||||
|
@ -64,6 +65,20 @@ const imports = [
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
|
ClientsModule.register([
|
||||||
|
{
|
||||||
|
name: GEOGRAPHY_SERVICE,
|
||||||
|
transport: Transport.RMQ,
|
||||||
|
options: {
|
||||||
|
//TODO read from config
|
||||||
|
urls: [`${process.env.MESSAGE_BROKER_URI}`],
|
||||||
|
queue: 'geography',
|
||||||
|
queueOptions: {
|
||||||
|
durable: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]),
|
||||||
CacheModule.registerAsync<RedisClientOptions>({
|
CacheModule.registerAsync<RedisClientOptions>({
|
||||||
imports: [ConfigModule],
|
imports: [ConfigModule],
|
||||||
useFactory: async (configService: ConfigService) => ({
|
useFactory: async (configService: ConfigService) => ({
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { CandidateEntity } from '@modules/ad/core/domain/candidate.entity';
|
import { CandidateEntity } from '@modules/ad/core/domain/candidate.entity';
|
||||||
import { Completer } from './completer.abstract';
|
|
||||||
import { MatchQuery } from '../match.query';
|
|
||||||
import { Step } from '../../../types/step.type';
|
|
||||||
import { CarpoolPathItem } from '@modules/ad/core/domain/value-objects/carpool-path-item.value-object';
|
import { CarpoolPathItem } from '@modules/ad/core/domain/value-objects/carpool-path-item.value-object';
|
||||||
import { RouteResponse } from '../../../ports/georouter.port';
|
import { RouteResponse } from '../../../ports/georouter.port';
|
||||||
|
import { Step } from '../../../types/step.type';
|
||||||
|
import { MatchQuery } from '../match.query';
|
||||||
|
import { Completer } from './completer.abstract';
|
||||||
|
|
||||||
export class RouteCompleter extends Completer {
|
export class RouteCompleter extends Completer {
|
||||||
protected readonly type: RouteCompleterType;
|
protected readonly type: RouteCompleterType;
|
||||||
|
@ -48,7 +48,10 @@ export class RouteCompleter extends Completer {
|
||||||
): Promise<RouteResponse> =>
|
): Promise<RouteResponse> =>
|
||||||
this.query.routeProvider.getRoute({
|
this.query.routeProvider.getRoute({
|
||||||
waypoints: (candidate.getProps().carpoolPath as CarpoolPathItem[]).map(
|
waypoints: (candidate.getProps().carpoolPath as CarpoolPathItem[]).map(
|
||||||
(carpoolPathItem: CarpoolPathItem) => carpoolPathItem,
|
(carpoolPathItem: CarpoolPathItem) => ({
|
||||||
|
lon: carpoolPathItem.lon,
|
||||||
|
lat: carpoolPathItem.lat,
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
detailsSettings: detailsSettings,
|
detailsSettings: detailsSettings,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
import { QueryBase } from '@mobicoop/ddd-library';
|
import { QueryBase } from '@mobicoop/ddd-library';
|
||||||
import { AlgorithmType } from '../../types/algorithm.types';
|
|
||||||
import { Waypoint } from '../../types/waypoint.type';
|
|
||||||
import { Frequency, Role } from '@modules/ad/core/domain/ad.types';
|
import { Frequency, Role } from '@modules/ad/core/domain/ad.types';
|
||||||
import { MatchRequestDto } from '@modules/ad/interface/grpc-controllers/dtos/match.request.dto';
|
|
||||||
import { DateTimeTransformerPort } from '../../ports/datetime-transformer.port';
|
|
||||||
import {
|
import {
|
||||||
Path,
|
Path,
|
||||||
PathCreator,
|
PathCreator,
|
||||||
|
@ -11,8 +7,12 @@ import {
|
||||||
TypedRoute,
|
TypedRoute,
|
||||||
} from '@modules/ad/core/domain/path-creator.service';
|
} from '@modules/ad/core/domain/path-creator.service';
|
||||||
import { Point } from '@modules/ad/core/domain/value-objects/point.value-object';
|
import { Point } from '@modules/ad/core/domain/value-objects/point.value-object';
|
||||||
import { Route } from '../../types/route.type';
|
import { MatchRequestDto } from '@modules/ad/interface/grpc-controllers/dtos/match.request.dto';
|
||||||
|
import { DateTimeTransformerPort } from '../../ports/datetime-transformer.port';
|
||||||
import { GeorouterPort } from '../../ports/georouter.port';
|
import { GeorouterPort } from '../../ports/georouter.port';
|
||||||
|
import { AlgorithmType } from '../../types/algorithm.types';
|
||||||
|
import { Route } from '../../types/route.type';
|
||||||
|
import { Waypoint } from '../../types/waypoint.type';
|
||||||
|
|
||||||
export class MatchQuery extends QueryBase {
|
export class MatchQuery extends QueryBase {
|
||||||
id?: string;
|
id?: string;
|
||||||
|
@ -209,7 +209,10 @@ export class MatchQuery extends QueryBase {
|
||||||
pathCreator.getBasePaths().map(async (path: Path) => ({
|
pathCreator.getBasePaths().map(async (path: Path) => ({
|
||||||
type: path.type,
|
type: path.type,
|
||||||
route: await this.routeProvider.getRoute({
|
route: await this.routeProvider.getRoute({
|
||||||
waypoints: path.waypoints,
|
waypoints: path.waypoints.map((p) => ({
|
||||||
|
lon: p.lon,
|
||||||
|
lat: p.lat,
|
||||||
|
})),
|
||||||
}),
|
}),
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
|
@ -225,6 +228,7 @@ export class MatchQuery extends QueryBase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
console.log(e.stack || e);
|
||||||
throw new Error('Unable to find a route for given waypoints');
|
throw new Error('Unable to find a route for given waypoints');
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Role } from './ad.types';
|
|
||||||
import { Point } from './value-objects/point.value-object';
|
|
||||||
import { PathCreatorException } from './match.errors';
|
|
||||||
import { Route } from '../application/types/route.type';
|
import { Route } from '../application/types/route.type';
|
||||||
|
import { Role } from './ad.types';
|
||||||
|
import { PathCreatorException } from './match.errors';
|
||||||
|
import { Point } from './value-objects/point.value-object';
|
||||||
|
|
||||||
export class PathCreator {
|
export class PathCreator {
|
||||||
constructor(
|
constructor(
|
||||||
|
|
|
@ -1,35 +1,26 @@
|
||||||
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import { ClientProxy } from '@nestjs/microservices';
|
||||||
import { Observable, lastValueFrom } from 'rxjs';
|
import { Observable, lastValueFrom } from 'rxjs';
|
||||||
import { Inject, Injectable, OnModuleInit } from '@nestjs/common';
|
import { GEOGRAPHY_SERVICE } from '../ad.di-tokens';
|
||||||
import { ClientGrpc } from '@nestjs/microservices';
|
|
||||||
import { GRPC_GEOROUTER_SERVICE_NAME } from '@src/app.constants';
|
|
||||||
import {
|
import {
|
||||||
GeorouterPort,
|
GeorouterPort,
|
||||||
RouteRequest,
|
RouteRequest,
|
||||||
RouteResponse,
|
RouteResponse,
|
||||||
} from '../core/application/ports/georouter.port';
|
} from '../core/application/ports/georouter.port';
|
||||||
import { GEOGRAPHY_PACKAGE } from '../ad.di-tokens';
|
|
||||||
|
|
||||||
interface GeorouterService {
|
interface GeorouterService {
|
||||||
getRoute(request: RouteRequest): Observable<RouteResponse>;
|
getRoute(request: RouteRequest): Observable<RouteResponse>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class Georouter implements GeorouterPort, OnModuleInit {
|
export class Georouter implements GeorouterPort {
|
||||||
private georouterService: GeorouterService;
|
private georouterService: GeorouterService;
|
||||||
|
|
||||||
constructor(@Inject(GEOGRAPHY_PACKAGE) private readonly client: ClientGrpc) {}
|
constructor(
|
||||||
|
@Inject(GEOGRAPHY_SERVICE) private readonly client: ClientProxy,
|
||||||
onModuleInit() {
|
) {}
|
||||||
this.georouterService = this.client.getService<GeorouterService>(
|
|
||||||
GRPC_GEOROUTER_SERVICE_NAME,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
getRoute = async (request: RouteRequest): Promise<RouteResponse> => {
|
getRoute = async (request: RouteRequest): Promise<RouteResponse> => {
|
||||||
try {
|
return lastValueFrom(this.client.send('getRoute', request));
|
||||||
return await lastValueFrom(this.georouterService.getRoute(request));
|
|
||||||
} catch (error: any) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue