-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rabbitmq): optional direct reply-to
fix #109
- Loading branch information
1 parent
88c6295
commit 3b7625c
Showing
5 changed files
with
106 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { | ||
AmqpConnection, | ||
RabbitMQModule, | ||
RabbitRPC, | ||
} from '@golevelup/nestjs-rabbitmq'; | ||
import { INestApplication, Injectable } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
|
||
const testHandler = jest.fn(); | ||
|
||
const prefix = 'testRpcNoDirectReply'; | ||
const exchange = prefix; | ||
const routingKey = `${prefix}Route`; | ||
|
||
@Injectable() | ||
class RpcService { | ||
@RabbitRPC({ | ||
exchange, | ||
routingKey: [routingKey], | ||
queue: `${prefix}Queue`, | ||
}) | ||
handleSubscribe(message: object) { | ||
testHandler(message); | ||
return 'pong'; | ||
} | ||
} | ||
|
||
describe('Rabbit Direct Reply To', () => { | ||
let app: INestApplication; | ||
let amqpConnection: AmqpConnection; | ||
|
||
const rabbitHost = process.env.NODE_ENV === 'ci' ? 'rabbit' : 'localhost'; | ||
const uri = `amqp://rabbitmq:rabbitmq@${rabbitHost}:5672`; | ||
|
||
beforeEach(async () => { | ||
const moduleFixture = await Test.createTestingModule({ | ||
providers: [RpcService], | ||
imports: [ | ||
RabbitMQModule.forRoot(RabbitMQModule, { | ||
exchanges: [ | ||
{ | ||
name: exchange, | ||
type: 'topic', | ||
}, | ||
], | ||
uri, | ||
connectionInitOptions: { wait: true, reject: true, timeout: 3000 }, | ||
enableDirectReplyTo: false, | ||
}), | ||
], | ||
}).compile(); | ||
|
||
app = moduleFixture.createNestApplication(); | ||
amqpConnection = app.get<AmqpConnection>(AmqpConnection); | ||
await app.init(); | ||
}); | ||
|
||
it('should not receive subscribe messages because register handlers is disabled', async done => { | ||
await expect( | ||
amqpConnection.request({ | ||
exchange, | ||
routingKey, | ||
payload: 'ping', | ||
timeout: 2000, | ||
}), | ||
).rejects.toThrow(); | ||
|
||
setTimeout(() => { | ||
expect(testHandler).not.toHaveBeenCalled(); | ||
done(); | ||
}, 50); | ||
}); | ||
}); |
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