-
-
Notifications
You must be signed in to change notification settings - Fork 201
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
1 parent
441743c
commit e5e772b
Showing
10 changed files
with
327 additions
and
0 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,23 @@ | ||
# RabbitMQ Module | ||
|
||
[RabbitMQ](https://www.rabbitmq.com/) is a reliable and mature messaging and streaming broker, which is easy to deploy on cloud environments, on-premises, and on your local machine. It is currently used by millions worldwide. | ||
|
||
## Install | ||
|
||
```bash | ||
npm install @testcontainers/rabbitmq --save-dev | ||
``` | ||
|
||
## Examples | ||
|
||
<!--codeinclude--> | ||
[Connect:](../../packages/modules/rabbitmq/src/rabbitmq-container.test.ts) inside_block:start | ||
<!--/codeinclude--> | ||
|
||
<!--codeinclude--> | ||
[Set credentials:](../../packages/modules/rabbitmq/src/rabbitmq-container.test.ts) inside_block:credentials | ||
<!--/codeinclude--> | ||
|
||
<!--codeinclude--> | ||
[Publish and subscribe:](../../packages/modules/rabbitmq/src/rabbitmq-container.test.ts) inside_block:pubsub | ||
<!--/codeinclude--> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { Config } from "jest"; | ||
import * as path from "path"; | ||
|
||
const config: Config = { | ||
preset: "ts-jest", | ||
moduleNameMapper: { | ||
"^testcontainers$": path.resolve(__dirname, "../../testcontainers/src"), | ||
}, | ||
}; | ||
|
||
export default config; |
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 @@ | ||
{ | ||
"name": "@testcontainers/rabbitmq", | ||
"version": "10.9.0", | ||
"license": "MIT", | ||
"keywords": [ | ||
"rabbitmq", | ||
"testing", | ||
"docker", | ||
"testcontainers" | ||
], | ||
"description": "RabbitMQ module for Testcontainers", | ||
"homepage": "https://github.com/testcontainers/testcontainers-node#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/testcontainers/testcontainers-node" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/testcontainers/testcontainers-node/issues" | ||
}, | ||
"main": "build/index.js", | ||
"files": [ | ||
"build" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"prepack": "shx cp ../../../README.md . && shx cp ../../../LICENSE .", | ||
"build": "tsc --project tsconfig.build.json" | ||
}, | ||
"dependencies": { | ||
"testcontainers": "^10.9.0" | ||
}, | ||
"devDependencies": { | ||
"@types/amqplib": "^0.10.4", | ||
"amqplib": "^0.10.4" | ||
} | ||
} |
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 @@ | ||
export { RabbitMQContainer, StartedRabbitMQContainer } from "./rabbitmq-container"; |
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,68 @@ | ||
import amqp from "amqplib"; | ||
import { RabbitMQContainer } from "./rabbitmq-container"; | ||
|
||
describe("RabbitMQContainer", () => { | ||
jest.setTimeout(240_000); | ||
|
||
// start { | ||
it("should start, connect and close", async () => { | ||
const rabbitMQContainer = await new RabbitMQContainer().start(); | ||
|
||
const connection = await amqp.connect(rabbitMQContainer.getAmqpUrl()); | ||
await connection.close(); | ||
|
||
await rabbitMQContainer.stop(); | ||
}); | ||
// } | ||
|
||
// credentials { | ||
it("different username and password", async () => { | ||
const USER = "user"; | ||
const PASSWORD = "password"; | ||
|
||
const rabbitMQContainer = await new RabbitMQContainer() | ||
.withEnvironment({ | ||
RABBITMQ_DEFAULT_USER: USER, | ||
RABBITMQ_DEFAULT_PASS: PASSWORD, | ||
}) | ||
.start(); | ||
|
||
const connection = await amqp.connect({ | ||
username: USER, | ||
password: PASSWORD, | ||
port: rabbitMQContainer.getMappedPort(5672), | ||
}); | ||
|
||
await connection.close(); | ||
|
||
await rabbitMQContainer.stop(); | ||
}); | ||
// } | ||
|
||
// pubsub { | ||
it("test publish and subscribe", async () => { | ||
const QUEUE = "test"; | ||
const PAYLOAD = "Hello World"; | ||
|
||
const rabbitMQContainer = await new RabbitMQContainer().start(); | ||
const connection = await amqp.connect(rabbitMQContainer.getAmqpUrl()); | ||
|
||
const channel = await connection.createChannel(); | ||
await channel.assertQueue(QUEUE); | ||
|
||
channel.sendToQueue(QUEUE, Buffer.from(PAYLOAD)); | ||
|
||
await new Promise((resolve) => { | ||
channel.consume(QUEUE, (message) => { | ||
expect(message?.content.toString()).toEqual(PAYLOAD); | ||
resolve(true); | ||
}); | ||
}); | ||
|
||
await channel.close(); | ||
await connection.close(); | ||
|
||
await rabbitMQContainer.stop(); | ||
}, 10_000); | ||
// } | ||
}); |
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,39 @@ | ||
import { AbstractStartedContainer, GenericContainer, StartedTestContainer, Wait } from "testcontainers"; | ||
|
||
const AMQP_PORT = 5672; | ||
const AMQPS_PORT = 5671; | ||
const HTTPS_PORT = 15671; | ||
const HTTP_PORT = 15672; | ||
const RABBITMQ_DEFAULT_USER = "guest"; | ||
const RABBITMQ_DEFAULT_PASS = "guest"; | ||
|
||
export class RabbitMQContainer extends GenericContainer { | ||
constructor(image = "rabbitmq:3.12.11-management-alpine") { | ||
super(image); | ||
this.withExposedPorts(AMQP_PORT, AMQPS_PORT, HTTPS_PORT, HTTP_PORT) | ||
.withEnvironment({ | ||
RABBITMQ_DEFAULT_USER, | ||
RABBITMQ_DEFAULT_PASS, | ||
}) | ||
.withWaitStrategy(Wait.forLogMessage("Server startup complete")) | ||
.withStartupTimeout(30_000); | ||
} | ||
|
||
public override async start(): Promise<StartedRabbitMQContainer> { | ||
return new StartedRabbitMQContainer(await super.start()); | ||
} | ||
} | ||
|
||
export class StartedRabbitMQContainer extends AbstractStartedContainer { | ||
constructor(startedTestContainer: StartedTestContainer) { | ||
super(startedTestContainer); | ||
} | ||
|
||
public getAmqpUrl(): string { | ||
return `amqp://${this.getHost()}:${this.getMappedPort(AMQP_PORT)}`; | ||
} | ||
|
||
public getAmqpsUrl(): string { | ||
return `amqps://${this.getHost()}:${this.getMappedPort(AMQPS_PORT)}`; | ||
} | ||
} |
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,13 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": [ | ||
"build", | ||
"jest.config.ts", | ||
"src/**/*.test.ts" | ||
], | ||
"references": [ | ||
{ | ||
"path": "../../testcontainers" | ||
} | ||
] | ||
} |
Oops, something went wrong.