access reactor inside ApplicationSession

#1

Hello everyone,

i am new to crossbar and i would like to access the reactor from my ApplicationSession. That is because inside my app i would like to use SQLAlchemy as ORM. With alchimia there is a way of using (at least some) of the features of SQLAlchemy through twisted. I establish the connection in the onJoin() method of my application (i take it from the database examples in the documentation that this is the place where to this). To be able to connect to the database i need to initialize a connection using alchimia and to do so i need the reactor created by the ApplicationRunner.

As far as i understand it there is no direct way to access the reactor from an ApplicationSession. Therefore i simply modified the ApplicationSession and ApplicationRunner classes to push a reference to the reactor when it is called in the run() method of the ApplicationRunner. After a brief test it seems to work fine.

Now the question. I have never worked with twisted before and so i’m not sure if this is the way to go or if there is another more elegant way. Is there another or better way to access the reactor from an ApplicationSession? Could using the same reactor for crossbar and alchimia end up in a performance bottleneck or even worse problems?

I think i might not be the only one for whom it would be interesting to use some database abstraction through alchimia/sqlalchemy instead of using the bare metal way with a background thread pool and postgresql or another database and raw sql queries.

cheers mo

0 Likes