primer cambio

This commit is contained in:
beseira13
2026-01-19 12:12:38 -03:00
parent 5f59dba52d
commit 44990f015a
4759 changed files with 588702 additions and 0 deletions

40
node_modules/amqplib/examples/stream_queues/README.md generated vendored Normal file
View File

@@ -0,0 +1,40 @@
RabbitMQ Stream Examples
---
The [stream queues](https://www.rabbitmq.com/streams.html) are available starting from RabbitMQ 3.9
These examples show how to use stream queues with the lib.
Send a message to a stream queue
```
node send_stream.js
```
Receive all the messages from stream queue:
```
node receive_stream.js
```
Consumers can be configured to receive messages using an offset via the `x-stream-offset` argument. e.g.
```js
channel.consume(queue, onMessage, {
noAck: false,
arguments: {
'x-stream-offset': 'first'
}
});
```
RabbitMQ supports six different types of offset, however specifying them can be
| Offset Type | Example Value | Notes |
|-----------|----------------------------------------------------------|-------|
| First | `{'x-stream-offset':'first'}` | Start from the first message in the log |
| Last | `{'x-stream-offset':'last'}` | Start from the last "chunk" of messages (could be multiple messages) |
| Next | `{'x-stream-offset':'next'}` | Start from the next message (the default) |
| Offset | `{'x-stream-offset':5}` | a numerical value specifying an exact offset to attach to the log at |
| Timestamp | `{'x-stream-offset':{'!':'timestamp',value:1686519750}}` | a timestamp value specifying the point in time to attach to the log at. The timestamp must be the number of seconds since 00:00:00 UTC, 1970-01-01. Consumers can receive messages published a bit before the specified timestamp. |
| Interval | `{'x-stream-offset':'1h'}` | the time interval relative to current time to attach the log at. Valid units are Y, M, D, h, m and s |
See https://www.rabbitmq.com/streams.html#consuming for more details

View File

@@ -0,0 +1,14 @@
{
"name": "stream_queues",
"version": "1.0.0",
"description": "An example demonstrating use of stream queues",
"main": "n",
"dependencies": {
"amqplib": "^0.10.3"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC"
}

View File

@@ -0,0 +1,55 @@
const amqp = require('amqplib');
(async () => {
try {
const connection = await amqp.connect('amqp://localhost');
process.once('SIGINT', connection.close);
const channel = await connection.createChannel();
const queue = 'my_first_stream';
// Define the queue stream
// Mandatory: exclusive: false, durable: true autoDelete: false
await channel.assertQueue(queue, {
exclusive: false,
durable: true,
autoDelete: false,
arguments: {
'x-queue-type': 'stream', // Mandatory to define stream queue
'x-max-length-bytes': 2_000_000_000 // Set the queue retention to 2GB else the stream doesn't have any limit
}
});
channel.qos(100); // This is mandatory
channel.consume(queue, (msg) => {
console.log(" [x] Received '%s'", msg.content.toString());
channel.ack(msg); // Mandatory
}, {
noAck: false,
arguments: {
/*
Here you can specify the offset: : first, last, next, offset, timestamp and interval, i.e.
'x-stream-offset': 'first'
'x-stream-offset': 'last'
'x-stream-offset': 'next'
'x-stream-offset': 5
'x-stream-offset': { '!': 'timestamp', value: 1686519750 }
'x-stream-offset': '1h'
The timestamp must be the desired number of seconds since 00:00:00 UTC, 1970-01-01
The interval units can be Y, M, D, h, m, s
*/
'x-stream-offset': 'first'
}
});
console.log(' [*] Waiting for messages. To exit press CTRL+C');
}
// Catch and display any errors in the console
catch(e) {
console.log(e)
}
})();

View File

@@ -0,0 +1,38 @@
const amqp = require('amqplib');
(async () => {
try {
const connection = await amqp.connect('amqp://localhost');
process.once('SIGINT', connection.close);
const channel = await connection.createChannel();
const queue = 'my_first_stream';
const msg = `Hello World! ${Date.now()}`;
// Define the queue stream
// Mandatory: exclusive: false, durable: true autoDelete: false
await channel.assertQueue(queue, {
exclusive: false,
durable: true,
autoDelete: false,
arguments: {
'x-queue-type': 'stream', // Mandatory to define stream queue
'x-max-length-bytes': 2_000_000_000 // Set the queue retention to 2GB else the stream doesn't have any limit
}
});
// Send the message to the stream queue
await channel.sendToQueue(queue, Buffer.from(msg));
console.log(" [x] Sent '%s'", msg);
await channel.close();
// Close connection
connection.close();
}
// Catch and display any errors in the console
catch(e) {
console.log(e)
}
})();