-
Notifications
You must be signed in to change notification settings - Fork 3
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
14 changed files
with
2,075 additions
and
5,231 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,15 @@ | ||
## v1.0.0 | ||
- [Breaking Change] | ||
- Queues in RabbitMQ created by v0.1.0 must be re-create because retry/deduplication feature cause queue configuration changed | ||
- Rename configuration to make it more relevant with amqplib configuration, please follow README to validate your configuration | ||
- queue.channel => queue.amqp | ||
- queue.channel.assert => queue.amqp.queueAssert | ||
- queue.consume => queue.amqp.consume | ||
- [Add] | ||
- Add retry feature by RabbitMQ requeue or using [rabbitmq-delayed-message-exchange](https://github.com/rabbitmq/rabbitmq-delayed-message-exchange) plugin | ||
- Add deduplication feature using [rabbitmq-message-deduplication](https://github.com/noxdafox/rabbitmq-message-deduplication) plugin | ||
- [Fix] | ||
- Fix bug not apply queue configuration when assert queue | ||
|
||
## v0.1.0 | ||
- First release |
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,10 @@ | ||
FROM rabbitmq:3-management | ||
|
||
ADD https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.5.0/elixir-1.10.4.ez /opt/rabbitmq/plugins/ | ||
ADD https://github.com/noxdafox/rabbitmq-message-deduplication/releases/download/0.5.0/rabbitmq_message_deduplication-0.5.0.ez /opt/rabbitmq/plugins/ | ||
|
||
ADD https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases/download/3.8.9/rabbitmq_delayed_message_exchange-3.8.9-0199d11c.ez /opt/rabbitmq/plugins/ | ||
|
||
RUN chown rabbitmq:rabbitmq /opt/rabbitmq/plugins/*.ez \ | ||
&& rabbitmq-plugins enable --offline rabbitmq_message_deduplication \ | ||
&& rabbitmq-plugins enable --offline rabbitmq_delayed_message_exchange |
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,10 @@ | ||
# Build image | ||
|
||
docker build -t moleculer-rabbitmq/rabbitmq:latest . | ||
|
||
# Push image | ||
|
||
docker push moleculer-rabbitmq/rabbitmq:latest | ||
|
||
# Run container | ||
docker run -d --name rabbitmq -p 15672:15672 -p 5672:5672 taina/rabbitmq:latest |
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,75 @@ | ||
const { ServiceBroker } = require("moleculer"); | ||
const QueueMixin = require("../../index"); | ||
|
||
let broker = new ServiceBroker({ | ||
logger: console, | ||
transporter: "TCP", | ||
}); | ||
|
||
const queueMixin = QueueMixin({ | ||
connection: "amqp://localhost", | ||
asyncActions: true, // Enable auto generate .async version for actions | ||
}); | ||
|
||
broker.createService({ | ||
name: "consumer", | ||
version: 1, | ||
|
||
mixins: [ | ||
queueMixin, | ||
], | ||
|
||
settings: { | ||
amqp: { | ||
connection: "amqp://localhost", // You can also override setting from service setting | ||
}, | ||
}, | ||
|
||
actions: { | ||
hello: { | ||
queue: { // Enable queue for this action | ||
// Options for AMQP queue | ||
amqp: { | ||
queueAssert: { | ||
exclusive: false, // (boolean) if true, scopes the queue to the connection (defaults to false) | ||
durable: true, // (boolean) if true, the queue will survive broker restarts, modulo the effects of exclusive and autoDelete; this defaults to true if not supplied, unlike the others | ||
autoDelete: false, // (boolean) if true, the queue will be deleted when the number of consumers drops to zero (defaults to false) | ||
arguments: { // additional arguments, usually parameters for some kind of broker-specific extension e.g., high availability, TTL | ||
}, | ||
}, | ||
prefetch: 0, | ||
}, | ||
retryExchangeAssert: { | ||
durable: true, // (boolean) if true, the exchange will survive broker restarts. Defaults to true. | ||
autoDelete: false, // (boolean) if true, the exchange will be destroyed once the number of bindings for which it is the source drop to zero. Defaults to false. | ||
alternateExchange: null, // (string) an exchange to send messages to if this exchange can’t route them to any queues. | ||
arguments: { // additional arguments, usually parameters for some kind of broker-specific extension e.g., high availability, TTL | ||
}, | ||
}, | ||
retry: true, // Using rabbitmq default requeue logic (retry forever) | ||
// retry: { | ||
// max_retry: 3, | ||
// delay: (retry_count) => { | ||
// return retry_count * 1000; | ||
// }, | ||
// }, | ||
}, | ||
params: { | ||
name: "string|convert:true|empty:false", | ||
}, | ||
async handler(ctx) { | ||
this.logger.info(`[CONSUMER] PID: ${process.pid} Received job with name=${ctx.params.name}`); | ||
return new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
this.logger.info(`[CONSUMER] PID: ${process.pid} Processed job with name=${ctx.params.name}`); | ||
return reject(new Error("TEST")); | ||
}, 1000); | ||
}); | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
broker.start().then(() => { | ||
broker.repl(); | ||
}); |
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,49 @@ | ||
const { ServiceBroker } = require("moleculer"); | ||
const QueueMixin = require("../../index"); | ||
|
||
let broker = new ServiceBroker({ | ||
logger: console, | ||
transporter: "TCP", | ||
}); | ||
|
||
const queueMixin = QueueMixin({ | ||
connection: "amqp://localhost", | ||
asyncActions: true, // Enable auto generate .async version for actions | ||
}); | ||
|
||
broker.createService({ | ||
name: "publisher", | ||
version: 1, | ||
|
||
mixins: [ | ||
queueMixin, | ||
], | ||
|
||
settings: { | ||
amqp: { | ||
connection: "amqp://localhost", // You can also override setting from service setting | ||
}, | ||
}, | ||
|
||
async started() { | ||
await broker.waitForServices({ name: "consumer", version: 1 }); | ||
|
||
let name = "buggy_message"; | ||
const response = await broker.call("v1.consumer.hello.async", { | ||
// `params` is the real param will be passed to original action | ||
params: { | ||
name, | ||
}, | ||
// `options` is the real options will be passed to original action | ||
options: { | ||
timeout: 2000, | ||
}, | ||
}); | ||
this.logger.info(`[PUBLISHER] PID: ${process.pid} Called job with name=${name} response=${JSON.stringify(response)}`); | ||
name++; | ||
} | ||
}); | ||
|
||
broker.start().then(() => { | ||
broker.repl(); | ||
}); |
Oops, something went wrong.