-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(microservices): add support for topic exchange (rabbitmq) #14540
Open
kamilmysliwiec
wants to merge
7
commits into
master
Choose a base branch
from
feat/rmq-topic-exchange
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
823fbab
feat(microservices): add support for topic exchange (rabbitmq)
kamilmysliwiec daae5e7
Potential fix for code scanning alert no. 39: Incomplete string escap…
kamilmysliwiec e1a9f5f
test: increase timeout for the wildcard topic exchange test
kamilmysliwiec f2e9f93
chore: disable lint rule for rmq producer and consumer
kamilmysliwiec d6c361b
Merge branch 'feat/rmq-topic-exchange' of https://github.com/nestjs/n…
kamilmysliwiec 23e76fd
test: use unique queue name for rmq
kamilmysliwiec d2948d9
refactor: introduce wildcards attribute, use existing exchange
kamilmysliwiec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { MicroserviceOptions, Transport } from '@nestjs/microservices'; | ||
import { Test } from '@nestjs/testing'; | ||
import * as request from 'supertest'; | ||
import { RMQTopicExchangeController } from '../src/rmq/topic-exchange-rmq.controller'; | ||
|
||
describe('RabbitMQ transport (Topic Exchange - wildcards)', () => { | ||
let server: any; | ||
let app: INestApplication; | ||
|
||
beforeEach(async () => { | ||
const module = await Test.createTestingModule({ | ||
controllers: [RMQTopicExchangeController], | ||
}).compile(); | ||
|
||
app = module.createNestApplication(); | ||
server = app.getHttpAdapter().getInstance(); | ||
|
||
app.connectMicroservice<MicroserviceOptions>({ | ||
transport: Transport.RMQ, | ||
options: { | ||
urls: [`amqp://0.0.0.0:5672`], | ||
queue: 'test2', | ||
wildcards: true, | ||
}, | ||
}); | ||
await app.startAllMicroservices(); | ||
await app.init(); | ||
}); | ||
|
||
it(`should send message to wildcard topic exchange`, () => { | ||
return request(server).get('/topic-exchange').expect(200, 'wildcard.a.b'); | ||
}); | ||
|
||
afterEach(async () => { | ||
await app.close(); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
integration/microservices/src/rmq/topic-exchange-rmq.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,36 @@ | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { | ||
ClientProxy, | ||
ClientProxyFactory, | ||
Ctx, | ||
MessagePattern, | ||
RmqContext, | ||
Transport, | ||
} from '@nestjs/microservices'; | ||
import { lastValueFrom } from 'rxjs'; | ||
|
||
@Controller() | ||
export class RMQTopicExchangeController { | ||
client: ClientProxy; | ||
|
||
constructor() { | ||
this.client = ClientProxyFactory.create({ | ||
transport: Transport.RMQ, | ||
options: { | ||
urls: [`amqp://localhost:5672`], | ||
queue: 'test2', | ||
wildcards: true, | ||
}, | ||
}); | ||
} | ||
|
||
@Get('topic-exchange') | ||
async topicExchange() { | ||
return lastValueFrom(this.client.send<string>('wildcard.a.b', 1)); | ||
} | ||
|
||
@MessagePattern('wildcard.*.*') | ||
handleTopicExchange(@Ctx() ctx: RmqContext): string { | ||
return ctx.getPattern(); | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some plugins in rabbit use their own exchangeType, e.g.
x-delayed-message
, maybe it is worth to give the possibility to pass any values for exchangeType.