What's new in Channels 2 Excerpt

     Recently, I was going to enable Channels on an old Django project. Channels released version 2.0 on February 2 this year. This version contains many features that are not forward compatible. For the needs of new feature research and the convenience of the community, my new version of What's New summarise it in Chinese.

     1. Dependency requirements : Because of the dependence on the Py3 standard library asyncio, Channels must be version 3.5 or above, and some dependencies even require version 3.5.2 or above

     2. The design concept system has undergone great changes:

          2.1. Channel layer and process : v1 network front-end and application logic communicate cross-process message events through channel layer, v2 Django Code executes in a process through thread pool , combining network front-end and application logic.

          2.2. Application instance : All processing for a Socket is performed in a process class, and the Channel layer is only used for message broadcasting, such as the transmission of chat messages between different application instances.

          2.3. New consumers: V2 adopts a tortoise -on-turtle design, and every aspect of the system is designed as an ASGI application that includes consumers and routing systems.

          2.5. Completely asynchronous: Except for View and ORM, most of the rest are asynchronous code

     3. Removed components: The binding framework is completely removed

     Fourth, how to upgrade your code :

         4.1. The old routing and consumer functions are gone, and a new class-based consumer and ProtocolTypeRouter must be defined.

         4.2, channel_session and enforce_ordering are not needed

         4.3. The Auth mechanism is changed from the decorator to the AuthMiddlewareStack configuration, and the message reading method including the Session becomes self.scope["name"]

         4.4. The channel layer is no longer necessary, all except channels_redis are directly replaced by asynchronous scheduling, and the configuration and usage of the channel layer have also changed

         4.5. The Groups object does not exist, and its feature mechanism is replaced by several functions

         4.6, Delay Server can be replaced by asynchronous consumers

         4.7. The testing framework has been completely rewritten to be asynchronous.

   

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325790410&siteId=291194637
Recommended