Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
swantzter committed Jul 31, 2023
1 parent 436211b commit bfb6a4d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions examples/connection-per-vu.js
Original file line number Diff line number Diff line change
@@ -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'
})
}

0 comments on commit bfb6a4d

Please sign in to comment.