连接到AWS托管的Cassandra服务(MCS)

时间:2020-01-05 05:34:13

标签: c# amazon-web-services cassandra amazon-keyspaces

我最近开始使用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 

0 个答案:

没有答案