1

I am currently learning the basics of the Cassandra. I am using the Datastax java-driver to experiment with. Now I am currently working out the session structure.

What I am wondering about is how to handle session lifetime. On the following Datastax page I found information about this.

http://www.datastax.com/dev/blog/4-simple-rules-when-using-the-datastax-drivers-for-cassandra

Now the following sentence creates my question.

"Basically you will want to share the same cluster and session instances across your application."

What if I would try to build a REST-webservice which uses Cassandra. What would be considered the 'application' in this instance. Would I have to maintain the session in some sort of instance class while te webservice is running? Or should I create a session on a per-user basis (meaning that in theory multiple sessions could exist at the same time)?

Thizzer
  • 16,153
  • 28
  • 98
  • 139

1 Answers1

2

Yes. That would be your application.

Usually, any application running, even within a server, will have some "Main" class which starts up everything. Try to hook it up there.

Ravindranath Akila
  • 209
  • 3
  • 35
  • 45
  • So you mean I have to maintain the same session for all calls? :) – Thizzer Jun 13 '14 at 09:40
  • Yes, or mention the key space in each query. I prefer the latter since maintaining one session across a cluster of servers isn't practical. – Ravindranath Akila Jun 13 '14 at 09:42
  • But when using a per keyspace session, what should I do with queries which don't require a keyspace, for example the query to create a keyspace? – Thizzer Jun 13 '14 at 09:59
  • If I'm not mistaken such queries would have very little impact on performance as they run very rarely. Create a session just for that if you would like. – Ravindranath Akila Jun 13 '14 at 10:00
  • Oke, so when using a CREATE KEYSPACE query I should just create and after the query immediately close a session? – Thizzer Jun 13 '14 at 10:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/55560/discussion-between-mrthys-and-ravindranath-akila). – Thizzer Jun 13 '14 at 10:05
  • But yes, if the sole purpose of that run is to create the key space. Once the application is up and running use a new one. Won't creating the key space via CQL be easier? – Ravindranath Akila Jun 13 '14 at 10:05
  • Yes that would be easier, but if I would want the application to create the entire setup, it would have to check on startup if the setup hasn't already been created. – Thizzer Jun 16 '14 at 07:15