-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
305 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
server/apps/gateway/src/pubsub/pubsub.gateway.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Controller, Get, Param } from '@nestjs/common'; | ||
import { PubSubGatewayService } from './pubsub.gateway.service'; | ||
|
||
@Controller('pubsub') | ||
export class PubSubGatewayController { | ||
constructor(private readonly pubSubGatewayService: PubSubGatewayService) {} | ||
|
||
@Get('test') | ||
async test() { | ||
return this.pubSubGatewayService.test(); | ||
} | ||
|
||
@Get('listen/:subscriptionName') | ||
async listenForMessages(@Param('subscriptionName') subscriptionName: string) { | ||
return this.pubSubGatewayService.listenForMessages(subscriptionName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Inject } from '@nestjs/common'; | ||
import { ClientGrpc } from '@nestjs/microservices'; | ||
import { Observable } from 'rxjs'; | ||
|
||
interface PubSubServiceClient { | ||
test(request: {}): Observable<{ message: string }>; | ||
listenForMessages(request: { subscriptionName: string }): Observable<{ status: string, message: string }>; | ||
} | ||
|
||
@Injectable() | ||
export class PubSubGatewayService { | ||
private pubSubService: PubSubServiceClient; | ||
|
||
constructor(@Inject('PUBSUB_SERVICE') private readonly client: ClientGrpc) {} | ||
|
||
onModuleInit() { | ||
this.pubSubService = this.client.getService<PubSubServiceClient>('PubSubService'); | ||
} | ||
t | ||
async test() { | ||
const result = await this.pubSubService.test({}).toPromise(); | ||
return result.message; | ||
} | ||
|
||
async listenForMessages(subscriptionName: string) { | ||
const result = await this.pubSubService.listenForMessages({ subscriptionName }).toPromise(); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ClientsModule, Transport } from '@nestjs/microservices'; | ||
import { PubSubGatewayController } from './pubsub.gateway.controller'; | ||
import { PubSubGatewayService } from './pubsub.gateway.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
ClientsModule.register([ | ||
{ | ||
name: 'PUBSUB_SERVICE', | ||
transport: Transport.GRPC, | ||
options: { | ||
package: 'googlecloudstorage', | ||
protoPath: 'src/proto/upload.proto', | ||
url: '0.0.0.0:50051', | ||
}, | ||
}, | ||
]), | ||
], | ||
controllers: [PubSubGatewayController], | ||
providers: [PubSubGatewayService], | ||
}) | ||
export class PubSubModule {} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Controller } from '@nestjs/common'; | ||
import { GrpcMethod } from '@nestjs/microservices'; | ||
import { PubSubService } from './pubsub.service'; | ||
|
||
@Controller() | ||
export class PubSubController { | ||
constructor(private readonly pubSubService: PubSubService) {} | ||
|
||
@GrpcMethod('PubSubService', 'Test') | ||
test(): { message: string } { | ||
return { message: 'PubSub service is active!' }; | ||
} | ||
|
||
@GrpcMethod('PubSubService', 'ListenForMessages') | ||
async listenForMessages(data: { subscriptionName: string }): Promise<{ status: string, message: string }> { | ||
try { | ||
const result = await this.pubSubService.listenForMessages(data.subscriptionName); | ||
return { status: 'success', message: result as string }; | ||
} catch (error) { | ||
return { status: 'error', message: error.message }; | ||
} | ||
} | ||
} |
Oops, something went wrong.