簡體   English   中英

連接到 AWS Managed Cassandra Service (MCS)

[英]Connecting to AWS Managed Cassandra Service (MCS)

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

您需要使用 SSL/TLS。 所以你的直覺是正確的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM