Last active
February 16, 2022 11:21
-
-
Save relistan/868761aae7f92300ad319b07e5648cc9 to your computer and use it in GitHub Desktop.
Connecting to Cassandra/SSL from JRuby with Datastax driver
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
def connect(addresses, dc_name) | |
builder = CqlSession.builder() | |
.withLocalDatacenter(dc_name) | |
addresses.each do |a| | |
(host, port) = a.split(/:/) | |
port ||= 9042 | |
builder | |
.addContactPoint(InetSocketAddress.new(host.to_java_string, port.to_i)) | |
.withAuthCredentials('[redacted]', '[redacted]') | |
.withSslContext(SSLContext.getDefault) | |
end | |
builder.build | |
end | |
session = connect(%w{the-db-adddress.aivencloud.com:11172}, 'aiven') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment