Reputation: 19
I'm using c# driver for Cassandra with multi-threads processing. At first, I tried to create a connection and execute command and then close the connection after done the work. But it's seem not to work for me, sometimes it's got an exception that No hosts available.
So, I changed to working with static connection. it's seem to work as well. But when thread is working too fast, it's broken again. I've to put some Thread.Sleep for 1 second then it works.
And with this static solution, I tried to use Asynchronous process, BeginExecute and it's not work for me as well, exception No Hosts Available.
So, anyone has better ideas or better implementation on multi-threads processing working with Cassandra c# driver, it would be appreciate if you can share.
Thank you in advance.
Cheers, Kin
Upvotes: 1
Views: 1743
Reputation: 101
If you use asynchronous method,it looks like that:
Statement sta=new SimpleStatement("Select * from XXX where XXX;");
session.ExecutAsync(sta);
Upvotes: 1
Reputation: 4002
Make sure your setup is satisfying the connection requirements
The C# driver should definitely work in a multi-threading environment (1 cluster object, 1 session object/keyspace)
It's difficult to say why you are seeing the NoHostAvailable exception without seeing any code.
Upvotes: 0
Reputation:
CassandraSession can only have one connection at a time. It probably isn't thread safe now that I think about it. But the Connection Pool is thread safe, so if you use that you will always have a high availability connection
Upvotes: 1