Simple real-time messaging in web applications.
The main goal of Centrifuge is the same as of Pusher or Pubnub services. The main difference is that Centrifuge is open-source and requires installation. Centrifuge is most similar to Faye
Centrifuge is built on top of Tornado - extremely fast and mature Python's async web server.
Centrifuge uses ZeroMQ steroid sockets for internal communication and publish/subscribe operations. There is also support for Redis PUB/SUB, so you can use it instead of ZeroMQ. You can also run full-featured instance of Centrifuge without extra dependencies on ZeroMQ and Redis - in this case you are limited in using only SINGLE instance of Centrifuge.
To connect to Centrifuge from browser pure Websockets or SockJS library can be used.
Centrifuge comes with administrative web interface to manage project/namespace structure and monitor important messages.
Persistent data (projects, namespaces) by default stored in SQLite database. But when running Centrifuge instance processes on different machines you should use MongoDB or PostgreSQL backends instead of SQLite.
Please,
- read the documentation
- look at examples.
- Asynchronous backend on top of Tornado
- Different backends for PUB/SUB operations
- SockJS and pure Websockets endpoints
- Simple javascript client
- Presence and history data for channels
- Web interface for managing your projects
- Flexible channel settings through namespaces
var centrifuge = new Centrifuge({
url: 'http://localhost:8000/connection', // Centrifuge SockJS connection endpoint
token: 'TOKEN', // token based on project's secret key, project ID and user ID
project: 'PROJECT_ID', // project ID from Centrifuge admin interface
user: 'USER_ID' // your application user ID (can be empty for anonymous access)
});
centrifuge.on('connect', function() {
console.log('connected');
var subscription = centrifuge.subscribe('django', function(message) {
// message from channel received
console.log(message);
});
subscription.on('ready', function(){
subscription.presence(function(message) {
// information about who connected to channel at moment received
});
subscription.history(function(message) {
// information about last messages sent into channel received
});
subscription.on('join', function(message) {
// someone connected to channel
});
subscription.on('leave', function(message) {
// someone disconnected from channel
});
});
});
centrifuge.on('disconnect', function(){
console.log('disconnected');
});
centrifuge.connect();
For more information about javascript client API see documentation chapter
To run tests type the following from tests
directory (centrifuge
must be in PYTHONPATH):
# IMPORTANT! Tests clear Redis database on every running. Be aware of this.
python -m unittest discover -p 'test_*.py'
Pull requests are welcome! But, please, follow next principles:
- keep things as simple as possible
- pep8
- python 2.6, 2.7 and 3.3 compatible
P.S. If BSD license of Centrifuge does not allow you to use it, tell me and I'll consider to change license.