连接到aws管理的cassandra服务(mcs)

sd2nnvve  于 2021-06-10  发布在  Cassandra
关注(0)|答案(1)|浏览(405)

我最近开始使用aws的cassandra托管服务,并尝试以编程方式连接到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
qnyhuwrf

qnyhuwrf1#

您需要使用ssl/tls。所以你的直觉是正确的。

相关问题