carrotmq
a much easy way to use rabbitmq
APIDOC
usage
const CarrotMQ = ;//var rabbitmqSchema = require('rabbitmq-schema');const rabbitmqSchema = CarrotMQschema; //see https://www.npmjs.com/package/rabbitmq-schemaconst schema = exchange: 'exchange0' type: 'topic' bindings: routingPattern: 'foo.bar.#' destination: queue: 'fooQueue' messageSchema: {} ;const mq = 'amqp://localhost' schema; const publisher = 'amqp://localhost'; //also can use without schema mq; mq;mq;
Message Validation
messageSchema
defines as json-schema on queue. Message will be validate when they comes.
If failed while validation, a validateError:${queue}
event will emit.
If no listener attached on this event, this fail will be silent ignore and message will be acked.
const schema = exchange: 'exchange0' type: 'topic' bindings: routingPattern: 'foo.bar.#' destination: queue: 'fooQueue' messageSchema: title: 'push-target' type: 'object' properties: userIds: type: 'array' message: type: 'object' properties: text: type: 'string' title: type: 'string' required: 'text' 'title' required: 'userIds' 'message' ;const mq = 'amqp://localhost' schema;mq;mq
RPC
mq;
If you prefer to use named queue rather than temp queue, you can set in config like
const mq = 'amqp://localhost' null callbackQueue: queue: 'carrotmq.rpc.callback'
Or
mq
RPC Over Exchange
//{// routingPattern: 'rpc.#',// destination: {// queue: 'rpcQueue',// messageSchema: {}// }// } app; let time = ;app // if target exchange is an topic or fanout exchange, only the first reply will be accepted.
events
ready
emit after connection established
mq;
error
emit when something happened
mq;
message
emit when message come
mq
close
emit when connection close
mq;
upgrade
V4 to V5
Because of rewritten in TypeScript, some export has changed before:
const CarrotMQ =
after:
const CarrotMQ =
V2 to V3
breaking change
- mq.rpc() and mq.rpcExchange() method remove the 4th consumer argument.And using Promise
used to
mq;
now can replaced by
let reply = await mq; try await ; reply; catch e reply;