我最近开始使用 AWS 的 Cassandra Managed Service 产品,并尝试以编程方式连接到 AWS 在其文档中显示的示例密钥表。我已经下载了 Cassandra c# 驱动程序并获得了生成的服务凭据。我现在遇到的问题是连接到集群(cluster.Connect())。我尝试在 .Connect 中使用各种不同的集群名称,但没有运气。任何人都知道集群名称应该是,或者在哪里可以找到它?另外,还有什么我没有的吗?这是否需要 TLS 连接编程才能工作?
我收到的错误是“找不到主机”:
using System;
using Cassandra;
namespace SampleConnect
{
class Program
{
static void Main(string[] args)
{
var cluster = Cluster.Builder()
.AddContactPoints("cassandra.us-east-2.amazonaws.com")
.WithPort(9142)
//.WithLoadBalancingPolicy(new DCAwareRoundRobinPolicy("AWS_VPC_AP_SOUTHEAST_2"))
.WithAuthProvider(new PlainTextAuthProvider("credential username", "crededential password"))
.Build();
// Connect to the nodes using a keyspace
var session = cluster.Connect();
// Get name of a Cluster
Console.WriteLine("The cluster's name is: " + cluster.Metadata.ClusterName);
// Execute a query on a connection synchronously
var rs = session.Execute("SELECT * FROM tutorialtable");
// Iterate through the RowSet
foreach (var row in rs)
{
var value = row.GetValue<string>("keyspace_name");
Console.WriteLine(value);
// Do something with the value
}
}
}
}
错误信息:
尝试查询的所有主机都失败(尝试了 3.17.137.4:9042: SocketException '连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立连接失败,因为连接的主机没有响应。')
堆栈跟踪:
at Cassandra.Connections.ControlConnection.<Connect>d__39.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
at Cassandra.Connections.ControlConnection.<InitAsync>d__36.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
at Cassandra.Tasks.TaskHelper.<WaitToCompleteAsync>d__10.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Cassandra.Cluster.<Cassandra-SessionManagement-IInternalCluster-OnInitializeAsync>d__50.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Cassandra.ClusterLifecycleManager.<InitializeAsync>d__3.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
at Cassandra.Cluster.<Cassandra-SessionManagement-IInternalCluster-ConnectAsync>d__47`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Cassandra.Cluster.<ConnectAsync>d__46.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Cassandra.Tasks.TaskHelper.WaitToComplete(Task task, Int32 timeout)
at Cassandra.Tasks.TaskHelper.WaitToComplete[T](Task`1 task, Int32 timeout)
at Cassandra.Cluster.Connect(String keyspace)
at Cassandra.Cluster.Connect()
at LoadBusinessData.Program.Main(String[] args) in Program.cs:line 20