I have a console.log in my javascript that verified is the newly created 
Feed that got sent. This is my binding, consumers and routing class:

#bindings.py
class FeedBinding(WebsocketBinding):

    model = Feed
    stream = "feed"
    fields = ["__all__"]

    @classmethod
    def group_names(cls, instance):
        return ["feed-grp", ]

    def has_permission(self, user, action, pk):
                return True

# consumers.py
class Demultiplexer(WebsocketDemultiplexer):

        print("consumers.py is run")
    consumers = {
        "feed": FeedBinding.consumer,
    }

        def connection_groups(self):
        return ["feed-grp", ]

# routing.py
channel_routing = [
    route_class(Demultiplexer, path="^/binding/"),
]


I still couldn't get the sending to work via admin or DRF API call when 
creating a `Feed` object. This somehow only happens in the production 
setup, runserver works fine.

Really appreciate your help, thanks for the great library!

Cheers
Zac

On Thursday, December 14, 2017 at 2:45:49 AM UTC+8, Andrew Godwin wrote:
>
> That is odd behaviour - have you tried to see if it's actually the group 
> send, or something like trying to send it twice? Can you post your binding 
> configuration?
>
> Andrew
>
> On Wed, Dec 13, 2017 at 4:14 AM, Zac Kwan <[email protected] <javascript:>
> > wrote:
>
>> In production, I have setup asgi, wsgi and nginx. My javascript frontend 
>> manage connected successfully base on the logs in runworker. However, when 
>> a new model is created (DRF API, Admin or Shell), it does not send a 
>> message to the group where my frontend is connected. It work perfectly in 
>> runserver.
>>
>> I had did some testing in the python manage.py shell and found out that 
>> it work when I try to send a group message myself first.
>>
>> $ python manage.py shell
>>
>> Python 3.6.2 (default, Aug 27 2017, 18:32:19) 
>>
>> [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
>>
>> Type "help", "copyright", "credits" or "license" for more information.
>>
>> (InteractiveConsole)
>>
>>
>> >>> from channels import Group
>> >>> from github_hook.models import Feed
>> >>>
>> >>> Feed.objects.create(name="foo") # Model is created but frontend did 
>> not receive any message
>> >>>
>> >>> Group("news").send({"text": "dsa"}) # After I do this, a print I had 
>> in consumers.py happened
>> >>> consumers.py is run!
>> >>>
>> >>>  Feed.objects.create(name="foo") # Now when i created a new object, 
>> frontend successfully received the mssage
>>
>>
>> The following is my CHANNEL_LAYERS setup:
>>
>> CHANNEL_LAYERS = {
>>     "default": {
>>         "BACKEND": "asgi_redis.RedisChannelLayer",
>>         "CONFIG": {
>>             "hosts": [os.environ.get('REDIS_URL', 
>> 'redis://localhost:6379')],
>>         },
>>         "ROUTING": "github_hook.routing.channel_routing",
>>     },
>> }
>>
>>
>> I had been on this for 2 weeks, still caa't figure out what is wrong. Can 
>> anyone help me figure out whats wrong? 
>>
>> It seems to me that my application that is served by WSGI, when created a 
>> model via admin, it does not trigger the message sending. It seems to be 
>> missing some init on consumers.py? 
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/eafc6aa0-d620-4e2a-af22-a715845fb463%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/eafc6aa0-d620-4e2a-af22-a715845fb463%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7287733f-0fba-41f0-894a-fe16772c96c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to