Created
December 22, 2016 23:32
-
-
Save mbroadst/6add091dea7ebea97236b0fc0a5b98da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const _ = require('lodash'), | |
Promise = require('bluebird'), | |
amqp = require('.'), | |
config = require('./test/integration/servicebus/eventhubs/config'); | |
var errorHandler = (partitionId, err) => console.warn(`==> RX ERROR (${partitionId}): ${err}`); | |
var messagesCounter = 0; | |
var messageHandler = (partitionId, msg) => { | |
++messagesCounter; | |
if (messagesCounter == 10000) { | |
console.timeEnd('benchmark'); | |
process.exit(0); | |
} | |
}; | |
var createReceiver = (client, partitionId, address) => { | |
return client.createReceiver(address) | |
.then(receiver => { | |
receiver.on('message', messageHandler.bind(null, partitionId)); | |
receiver.on('errorReceived', errorHandler.bind(null, partitionId)); | |
}); | |
} | |
function singleClientTest() { | |
console.log('single client'); | |
const client = new amqp.Client(amqp.Policy.EventHub); | |
client.connect(config.address) | |
.tap(() => console.time('benchmark')) | |
.then(() => [...Array(4)].map((_, idx) => createReceiver(client, idx, config.receiverLinkPrefix + idx))); | |
} | |
function multiClientTest() { | |
console.log('multiple clients'); | |
let clients = []; | |
Promise | |
.map(_.range(4), (_, idx) => { | |
let client = new amqp.Client(amqp.Policy.EventHub); | |
clients.push(client); | |
return client.connect(config.address); | |
}) | |
.tap(() => console.time('benchmark')) | |
.map((client, idx) => { | |
createReceiver(client, idx, config.receiverLinkPrefix + idx); | |
}); | |
} | |
if (process.argv[2] === 'multi') { | |
multiClientTest(); | |
} else { | |
singleClientTest(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment