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' + }) +}