Giter Club home page Giter Club logo

docker_channels's Introduction

docker_channels

Django channels used in docker environment with nginx, redis, and daphne

Important channels files:

  • routing.py -- similar to urls.py but for websockets
  • consumers.py -- can think of them as views kinda
  • settings.py
  • asgi.py

Within the consumer you define the functions to want to run/call. For example in my other project once a message is received I call the parse and return the resulting success/failure message via a return channel.

Important signals files:

  • signals.py
  • app.py
  • __init__.py

Additionally if you're running django-channels on windows (if you decide not to use the docker file for example), you'll need to install :

  • Redis-server (alternative is RabbitMQ)
  • pywin32 and pypiwin32 (through pip)

Some things to note:

  • The value entered in the form is irrelevant the output will always be the value hard-coded in de signals.py, I added the form in order to incorporate triggering the event after saving the form. (Didn't feel like making it too fancy).

How to use it?

Assuming you have docker-compose installed

docker-compose build
docker-compose up

I added a script that does the migration, it runs after 2 seconds. The connect to the app at http://192.168.99.100 , otherwise check your docker ip .

docker-machine ip

Once connected there are 2 ways to observe the functionality.

  1. Via browser terminal
  • open browser-console type document.ws.send(10)
  • the output can be observed on your working terminal (docker)
  1. Using the form link
  • Submit the form, and it prints in the terminal

For method one, there's an inline JS that allows this. If you choose to implement this setup or something similar, be sere to remove the line document.ws = socket; in the template. as this allows you to do the action described above.

docker_channels's People

Contributors

jdelgit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.