the-real-blackh / cassandra-cql

Haskell client for Cassandra's CQL protocol
BSD 3-Clause "New" or "Revised" License
27 stars 16 forks source link

What is the correct way to connect to a Cassandra server ? #20

Open yeyan opened 8 years ago

yeyan commented 8 years ago

Sorry for rising this as a issue, but it is a bit hard to figure out how to use this library.

root@b3e0266f401c:/# nodetool ring

Datacenter: SearchAnalytics
==========
Address     Rack        Status State   Load            Owns                Token                                       

172.17.0.2  rack1       Up     Normal  485.95 KB       ?                   -2758875854119677886     
{-# LANGUAGE OverloadedStrings #-}

import Data.UUID
import qualified Data.Text as T

import Database.Cassandra.CQL
import Control.Monad.IO.Class

import Data.Maybe

getOneSong :: Query style UUID (UUID)
getOneSong = query "select customer from status_by_customer where customer = ?"

test = do
    pool <- newPool [("172.17.0.2","")] "test_data" Nothing
    runCas pool $ do
        executeRows ANY getOneSong (fromJust $ fromString "c2cc10e1-57d6-4b6f-9899-38d972112d8c")

But I always get

failed to create a session due to temporary error (will retry) : NoAvailableServers

if I set the server to ("172.17.0.2", "b3e0266f401c"), the following error will rise:

failed to create a session due to permanent error (will rethrow) : getAddrInfo: does not exist (Servname not supported for ai_socktype)

And I am pretty sure I have exported all the port, that needed to connect to Cassandra, as my other programs are working fine with this docker.

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                                                                                                                      NAMES
b3e0266f401c        docker_cassandra    "/usr/local/bin/dse-e"   12 days ago         Up 50 minutes       4040/tcp, 7000/tcp, 7077/tcp, 7080-7081/tcp, 8012/tcp, 8090/tcp, 8983-8984/tcp, 9042/tcp, 9160/tcp, 9290/tcp, 10000/tcp, 50030/tcp, 50060/tcp, 61621/tcp   my-dse

Would you please show me an example that how to use this library to connect to Cassandra ?

wrl314 commented 8 years ago

The second entry in the Server tuple is a port number. So try newPool [("172.17.0.2","9042")] "test_data" Nothing