From bfb6a4d2a409f9d3e60d0a6524a7640befaba022 Mon Sep 17 00:00:00 2001 From: Svante Bengtson Date: Tue, 16 May 2023 18:11:18 +0200 Subject: [PATCH] add example --- examples/connection-per-vu.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 examples/connection-per-vu.js diff --git a/examples/connection-per-vu.js b/examples/connection-per-vu.js new file mode 100644 index 0000000..32c9270 --- /dev/null +++ b/examples/connection-per-vu.js @@ -0,0 +1,34 @@ +import Amqp from 'k6/x/amqp' +import exec from 'k6/execution' + +export const options = { + vus: 10, + duration: '30s', +} + +const url = "amqp://guest:guest@localhost:5672/" +const connIds = new Map() + +function getConnectionId (vuId) { + if (!connIds.has(vuId)) { + const connectionId = Amqp.start({ connection_url: url }) + connIds.set(vuId, connectionId) + return connectionId + } + return connIds.get(vuId) +} + +export default function () { + console.log("K6 amqp extension enabled, version: " + Amqp.version) + + const connectionId = getConnectionId(exec.vu.idInInstance) + const queueName = 'K6 queue' + + Amqp.publish({ + connection_id: connectionId, + queue_name: queueName, + exchange: '', + content_type: 'text/plain', + body: 'Ping from k6' + }) +}