Created
May 13, 2019 13:02
-
-
Save matteo-grella/a271dbe68f5e19960c10bd45b235de4a to your computer and use it in GitHub Desktop.
Create a RabbitMQ Connection
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
import com.rabbitmq.client.Connection | |
import com.rabbitmq.client.ConnectionFactory | |
/** | |
* Create a RabbitMQ Connection. | |
* | |
* @param host the host | |
* @param port the port | |
* @param username the username (can be null) | |
* @param password the username (can be null) | |
* | |
* return a new channel | |
*/ | |
fun buildConnection(host: String, port: Int, username: String?, password: String?): Connection { | |
val factory = ConnectionFactory() | |
factory.host = host | |
factory.port = port | |
if (username != null && password != null) { | |
factory.username = username | |
factory.password = password | |
} | |
factory.isAutomaticRecoveryEnabled = true // isn't automatic recovery enabled by default? | |
factory.requestedHeartbeat = 1800 // http://www.rabbitmq.com/heartbeats.html | |
return factory.newConnection() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment