
ru.tinkoff.gatling.amqp.client.AmqpConnectionPool.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gatling-amqp-plugin_2.13 Show documentation
Show all versions of gatling-amqp-plugin_2.13 Show documentation
Plugin for support performance testing with AMQP in Gatling
The newest version!
package ru.tinkoff.gatling.amqp.client
import java.util.concurrent.Executors
import com.rabbitmq.client.{Channel, Connection, ConnectionFactory}
import org.apache.commons.pool2.ObjectPool
import org.apache.commons.pool2.impl.{GenericObjectPool, GenericObjectPoolConfig}
class AmqpConnectionPool(factory: ConnectionFactory, consumerThreadsCount: Int) {
private val connection: Connection = factory.newConnection(Executors.newFixedThreadPool(consumerThreadsCount))
private val poolConfig = new GenericObjectPoolConfig[Channel]()
poolConfig.setMaxTotal(16)
private val channelPool: ObjectPool[Channel] = new GenericObjectPool[Channel](new AmqpChannelFactory(connection))
def createConsumerChannel: Channel = connection.createChannel()
def close(): Unit = {
if (connection != null) {
channelPool.close()
if (connection.isOpen) {
connection.close()
}
}
}
def channel: Channel = {
channelPool.borrowObject()
}
def returnChannel(ch: Channel): Unit = channelPool.returnObject(ch)
def invalidate(ch: Channel): Unit = channelPool.invalidateObject(ch)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy