Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ import { connectToRabbitMQ, consumeMessageFromQueue, createQueue, sendMessageToQ

const queueName = 'queue1';

// Stop the process from exiting before the transaction is sent
// eslint-disable-next-line @typescript-eslint/no-empty-function
setInterval(() => {}, 1000);

// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async () => {
const { connection, channel } = await connectToRabbitMQ();
await createQueue(queueName, channel);

const consumeMessagePromise = consumeMessageFromQueue(queueName, channel);

await Sentry.startSpan({ name: 'root span' }, async () => {
sendMessageToQueue(queueName, channel, JSON.stringify({ foo: 'bar01' }));
});

await consumeMessageFromQueue(queueName, channel);
await consumeMessagePromise;

await channel.close();
await connection.close();
})();
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@ export function sendMessageToQueue(queueName: string, channel: Channel, message:
}

async function consumer(queueName: string, channel: Channel): Promise<void> {
await channel.consume(
queueName,
message => {
if (message) {
channel.ack(message);
}
},
ACKNOWLEDGEMENT,
);
return new Promise((resolve, reject) => {
channel
.consume(
queueName,
message => {
if (message) {
channel.ack(message);
resolve();
} else {
reject(new Error('No message received'));
}
},
ACKNOWLEDGEMENT,
)
.catch(reject);
});
}

export async function consumeMessageFromQueue(queueName: string, channel: Channel): Promise<void> {
Expand Down
Loading