CassandraConnectionOptions
Description
Create connection options for an Apache Cassandra® database connection.
After you create an CassandraConnectionOptions
object, set the
connection options, test the connection, and save the data source, you can create an Apache
Cassandra database connection using the saved data source. The connection options include
the options required to make a Cassandra database connection.
Creation
To create a CassandraConnectionOptions
object, use the databaseConnectionOptions
function.
Properties
DataSourceName
— Data source name
string scalar
Data source name, specified as a string scalar. You can use the data source name in
the apacheCassandra
function to create a Cassandra database connection.
Example:
"ApacheCassandra"
Data Types: string
Vendor
— Database vendor
string scalar
This property is read-only.
Database vendor, specified as a string scalar. Set this property using the
vendor
input argument in the databaseConnectionOptions
function.
Example:
"Cassandra"
Data Types: string
ContactPoints
— Contact points
"localhost"
(default) | string scalar | string array
Contact points that are host addresses for one node or for multiple nodes in the Cassandra cluster, specified as a string scalar or string array. Specify a string scalar for one node. Or, specify a string array for multiple nodes.
You can specify a local host or the IP address of a different machine in the Cassandra cluster.
When you specify multiple nodes, if the connection to one host fails, then the
apacheCassandra
function connects to the other nodes in the cell array or
string array until a connection succeeds. If a connection attempt fails for all
specified nodes, the function displays an error message. If one or more nodes are not
available, enter multiple nodes in the string array to increase the likelihood of a
successful connection.
Data Types: string
PortNumber
— Port number
9042
(default) | positive numeric scalar
Port number for connection to the host, specified as a positive numeric scalar.
Data Types: double
SSLEnabled
— SSL-enabled connection
false
(default) | true
SSL-enabled connection, specified as the value false
or true
. Setting this argument to true
creates an SSL-enabled connection to the Cassandra database.
Data Types: logical
LoginTimeout
— Login timeout
5
(default) | positive numeric scalar
Login timeout, specified as a positive numeric scalar. The login timeout specifies the number of seconds that the C++ driver waits while trying to connect to the Cassandra database before throwing an error.
Data Types: double
RequestTimeout
— Request timeout
12
(default) | positive numeric scalar
This property is read-only.
Request timeout, specified as a positive numeric scalar. The request timeout indicates the number of seconds the database waits to return a CQL query before throwing an error.
Data Types: double
Object Functions
setoptions | Set Apache Cassandra database connection options |
testConnection | Test Apache Cassandra database connection |
reset | Reset Apache Cassandra database connection options to defaults |
saveAsDataSource | Save Apache Cassandra data source |
Examples
Create Cassandra Data Source and Set Connection Options
Configure an Apache™ Cassandra® database connection by creating a Cassandra data source, setting the Cassandra connection options, and saving the data source.
Create a Cassandra data source for a Cassandra database connection.
vendor = "Cassandra"; opts = databaseConnectionOptions("native",vendor)
opts = CassandraConnectionOptions with properties: DataSourceName: "" Vendor: "Cassandra" ContactPoints: "localhost" PortNumber: 9042 SSLEnabled: false LoginTimeout: 5 RequestTimeout: 12
opts
is an CassandraConnectionOptions
object with these properties:
DataSourceName
— Name of the data sourceVendor
— Database vendor nameContactPoints
— Contact pointsPortNumber
— Port numberSSLEnabled
— SSL-enabled connectionLoginTimeout
— Login timeoutRequestTimeout
— Request timeout
Configure the data source by setting the Cassandra connection options for the data source CassandraDataSource
, local host address for one node in the cluster, port number 9042
, SSL encryption that is disabled, login timeout of 5 seconds, and request timeout of 12 seconds.
opts = setoptions(opts, ... "DataSourceName","CassandraDataSource", ... "ContactPoints","localhost","PortNumber",9042, ... "SSLEnabled",false,"LoginTimeout",5, ... "RequestTimeout",12)
opts = CassandraConnectionOptions with properties: DataSourceName: "CassandraDataSource" Vendor: "Cassandra" ContactPoints: "localhost" PortNumber: 9042 SSLEnabled: false LoginTimeout: 5 RequestTimeout: 12
The setoptions
function sets the DataSourceName
, ContactPoints
, PortNumber
, SSLEnabled
, LoginTimeout
, and RequestTimeout
properties in the CassandraConnectionOptions
object.
Test the database connection with a blank user name and password. The testConnection
function returns the logical 1
, which indicates the database connection is successful.
username = ""; password = ""; status = testConnection(opts,username,password)
status = logical
1
Save the configured data source.
saveAsDataSource(opts)
Version History
Introduced in R2021a
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)