How are Django channels different than celery?

天涯浪子 提交于 2019-12-04 08:59:44

问题


Recently I came to know about Django channels. Can somebody tell me the difference between channels and celery, as well as where to use celery and channels.


回答1:


Channels in Django are meant for asynchronous handling of requests.
The standard model Django uses is Request-Response but that has significant limitations. We cannot do anything outside the restrictions of that model.
Channels came about to allow Web Socket support and building complex applications around Web Sockets, so that we can send multiple messages, manage sessions, etc.

Celery is a completely different thing, it is an asynchronous task queue/job queue based on distributed message passing. It is primarily for queuing tasks and scheduling them to run at specific intervals.

Simply put Channels are used when you need asynchronous data communication like a chat application, and Celery is for scheduling tasks and events like a server scraping the web for a certain type of news at fixed intervals.




回答2:


  • Channels in Django is for WebSocket, long-poll HTTP.

  • Celery is for background task, queue.




回答3:


Django channels gives to Django the ability to handle more than just plain HTTP requests, including Websockets and HTTP2. Think of this as 2 way duplex communication that happens asynchronously No browser refreshing. Multiple clients can send and receive data via websocket and django channels orchestrates this intercommunication example a group chat with simultaneously clients accessing at the same time. You can achieve background processing of long running code simliar to that of a celery to a certain extent, but the application of channels is different to that of celery.

Celery is an asynchronous task queue/job queue based on distributed message passing. As well as scheduling. In layman's terms, I want to fire and run a task in the background or I want to have a periodical task that fires and runs in the back on a set interval. You can also fire task in a synchronous way as well fire and wait until complete and continue. So the key difference is in the use case they serve and objectives of the frameworks




回答4:


Other answers, greatly explained the diff, but in facts Channels & Celery can both do asynchronous pooled tasks in common.

Channels and Celery both use a backend for messages and worker daemon(s). So the same kind of thing could be implemented with both.

But keep in mind that Celery is primary made for and can handle most issue of task pooling (retries, result backend, etc), where Channels is absolutely not made for.




回答5:


Django Channels:

beyond HTTP - to handle WebSockets, chat protocols, IoT protocols, and more.

  1. Passes messages between client and server (Full duplex connection)

  2. Handle HTTP and Web-sockets requests

  3. Asynchronous

Example :

  • Real time chat application
  • Update social feeds
  • Multiplayer game
  • Sending Notifications

Celery :

It’s a task queue with focus on real-time processing, while also supporting task scheduling.

  1. Perform long running background tasks

  2. Perform periodic tasks

  3. Asynchronous

Example :

  • Processing Videos/images
  • Sending bulk emails

Further reading

Example of Celery and Django Channels

Asynchronous vs Synchronous




回答6:


Channels is a project that takes Django and extends its abilities beyond HTTP - to handle Web-sockets, chat protocols, IoT protocols, and more. It’s built on a Python specification called ASGI.

Channels changes Django to weave asynchronous code underneath and through Django’s synchronous core, allowing Django projects to handle not only HTTP, but protocols that require long-running connections too - WebSockets, MQTT, chatbots, amateur radio, and more.

It does this while preserving Django’s synchronous and easy-to-use nature, allowing you to choose how you write your code - synchronous in a style like Django views, fully asynchronous, or a mixture of both. On top of this, it provides integrations with Django’s auth system, session system, and more, making it easier than ever to extend your HTTP-only project to other protocols.

It also bundles this event-driven architecture with channel layers, a system that allows you to easily communicate between processes, and separate your project into different processes.

Celery is an asynchronous task queue based on distributed message passing. It provides functionalities to run real-time operations and schedule some tasks to be executed later. These tasks can be executed asynchronous or synchronous, this means you may prefer to run them at the background or chain them to make one task to be fulfilled after the successful execution of an another task.



来源:https://stackoverflow.com/questions/38620969/how-are-django-channels-different-than-celery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!