# group\_send fired but consumer is not receiving

**URL:** <https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367>\
**Category:** Async/Channels\
**Created:** [January 29, 2025, 11:05pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367 "2025-01-29T23:05:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![B4sic101](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/b4sic101/32/25566_2.png) [@B4sic101](https://forum.djangoproject.com/u/B4sic101)\
**Post date:** [January 29, 2025, 11:05pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/1 "2025-01-29T23:05:55Z")

</div>

Currently, the only prints that are not outputting are the ones in the frNotifier, heres settings.py:

```python
CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels.layers.InMemoryChannelLayer"
    }
}

ASGI_APPLICATION = 'app_dependencies.asgi.application'

```

consumers.py:

```python
from channels.generic.websocket import WebsocketConsumer
from asgiref.sync import async_to_sync
from api.models import friendRequest
from api.models import User
import json

class FRConsumer(WebsocketConsumer):
    def connect(self):
        if self.scope["user"].is_anonymous:
            # Reject the connection
            self.close()
        else:
            # Accept the connection
            user = self.scope['user']
            self.group_name = f'noti_{user.userID}'
            async_to_sync(self.channel_layer.group_add(self.group_name, self.channel_name))
            self.accept()
    
    def disconnect(self, close_code):
        async_to_sync(self.channel_layer.group_discard(self.group_name, self.channel_name))
    
    def receive(self, text_data):
        print(f"{text_data}")
        jData = json.loads(text_data)
        reqID = jData["requestID"]
        receiverUserID = friendRequest.objects.filter(requestID=reqID).values("receiver")[0]["receiver"]
        senderUserID = friendRequest.objects.filter(requestID=reqID).values("sender")[0]["sender"]
        sender = User.objects.filter(userID=senderUserID).values("username")[0]["username"]
        targetGrp = f'noti_{receiverUserID}'
        receiver = User.objects.filter(userID=receiverUserID).values("username")[0]["username"]

        # Truth table variables
        print(f"""------------- TRUTH TABLE -------------
        Target Group: {targetGrp}
        Receiver: {receiver}
        Sender: {sender}
        Own Group Name: {self.group_name}
---------------- OUTPUTS ---------------""")

        try:
            print("Sending to..." + targetGrp)
            async_to_sync(
                self.channel_layer.group_send)(
                targetGrp,
                {
                    'type': 'frNotifier',
                    'requestID': reqID,
                    'sender': sender
                }
                )
            print("Succesfully sent message to group")
        except Exception:
            print("User not online")

    def frNotifier(self, textData):
        print("FRNotifier called")
        try:
            reqID = textData['requestID']
            sender = textData['sender']
            async_to_sync(self.send(textData=json.dumps({
                'requestID':reqID,
                'senderUsername': sender
            })))
            print("Friend request notification sent")
        except Exception as e:
            print("ERROR: User is not online for FR notification.")

```

My issue is that frNotifier is not being called on the receiving consumer’s/group’s end.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 29, 2025, 11:16pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/2 "2025-01-29T23:16:26Z")

</div>

How are you running your project?

> [@B4sic101](#):
>
> ` "BACKEND": "channels.layers.InMemoryChannelLayer"`

This is a really bad idea once you get beyond the stage of prototyping.

---

<div class="post-metadata">

**Author:** ![B4sic101](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/b4sic101/32/25566_2.png) [@B4sic101](https://forum.djangoproject.com/u/B4sic101)\
**Post date:** [January 29, 2025, 11:19pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/3 "2025-01-29T23:19:14Z")

</div>

To my knowledge I am only to use redis when I deploy the application not during prototyping. Not sure what the proper way is, I’m still quite a beginner - my bad. But I am running my project on localhost.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 29, 2025, 11:20pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/4 "2025-01-29T23:20:50Z")

</div>

> [@B4sic101](#):
>
> To my knowledge I am only to use redis when I deploy the application not during prototyping.

I only ever use Redis - even in development. I don’t know of any benefit or advantage to using that “InMemoryChannelLayer”.

---

<div class="post-metadata">

**Author:** ![B4sic101](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/b4sic101/32/25566_2.png) [@B4sic101](https://forum.djangoproject.com/u/B4sic101)\
**Post date:** [January 29, 2025, 11:21pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/5 "2025-01-29T23:21:55Z")

</div>

Was following the docs, I’ll switch to redis then and see if theres a difference.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 29, 2025, 11:23pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/6 "2025-01-29T23:23:32Z")

</div>

I’m not saying that this is the cause of this issue - only that it’s something that should be addressed sooner rather than later.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 29, 2025, 11:25pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/7 "2025-01-29T23:25:40Z")

</div>

What are you seeing in your logs from all the print statements? It might be helpful to see the complete console log from your testing.

---

<div class="post-metadata">

**Author:** ![B4sic101](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/b4sic101/32/25566_2.png) [@B4sic101](https://forum.djangoproject.com/u/B4sic101)\
**Post date:** [January 29, 2025, 11:27pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/8 "2025-01-29T23:27:03Z")

</div>

Well the WebSocket handshakes are completed and the outputs look like this:

```python
{"requestID":"5361f63d-c921-4043-9990-853dfc65e77b"}
------------- TRUTH TABLE -------------
        Target Group: noti_16bb0918-aa22-44e3-8864-8b639a915190
        Receiver: Frank
        Sender: Jerry Kole
        Own Group Name: noti_3f1e0afe-64ac-4ce4-b5e3-dd5cb4b4555e
---------------- OUTPUTS ---------------
Sending to...noti_16bb0918-aa22-44e3-8864-8b639a915190
Succesfully sent message to group

```

It just blacks out after the receive outputs and no output is given for the frNotifier.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 29, 2025, 11:30pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/9 "2025-01-29T23:30:41Z")

</div>

> [@B4sic101](#):
>
> `noti_16bb0918-aa22-44e3-8864-8b639a915190`

What output do you have showing that this is a valid group name with a connected user?

---

<div class="post-metadata">

**Author:** ![B4sic101](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/b4sic101/32/25566_2.png) [@B4sic101](https://forum.djangoproject.com/u/B4sic101)\
**Post date:** [January 29, 2025, 11:35pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/10 "2025-01-29T23:35:36Z")

</div>

Not sure how to check that with InMemoryChannelLayer. Would I have to create a model to keep track of this?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 29, 2025, 11:37pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/11 "2025-01-29T23:37:19Z")

</div>

You could print the users as they connect - and as long as there’s no disconnect message, that user should remain connected.

---

<div class="post-metadata">

**Author:** ![B4sic101](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/b4sic101/32/25566_2.png) [@B4sic101](https://forum.djangoproject.com/u/B4sic101)\
**Post date:** [January 29, 2025, 11:40pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/12 "2025-01-29T23:40:43Z")

</div>

Oh I did that already, the client’s channel is assigned to the correct group.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 29, 2025, 11:41pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/13 "2025-01-29T23:41:54Z")

</div>

But you haven’t shown that in the output you posted.

Please post the complete log, showing all the information from your test.

---

<div class="post-metadata">

**Author:** ![B4sic101](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/b4sic101/32/25566_2.png) [@B4sic101](https://forum.djangoproject.com/u/B4sic101)\
**Post date:** [January 29, 2025, 11:44pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/14 "2025-01-29T23:44:26Z")

</div>

```auto
WebSocket HANDSHAKING /ws/notifyFR/ [127.0.0.1:53960]
---- Jerry Kole with a userID of 3f1e0afe-64ac-4ce4-b5e3-dd5cb4b4555e is in the group noti_3f1e0afe-64ac-4ce4-b5e3-dd5cb4b4555e.
WebSocket CONNECT /ws/notifyFR/ [127.0.0.1:53960]
...
WebSocket HANDSHAKING /ws/notifyFR/ [127.0.0.1:44112]
---- Frank with a userID of 16bb0918-aa22-44e3-8864-8b639a915190 is in the group noti_16bb0918-aa22-44e3-8864-8b639a915190.
WebSocket CONNECT /ws/notifyFR/ [127.0.0.1:44112]

```

function:

```auto
def connect(self):
        if self.scope["user"].is_anonymous:
            # Reject the connection
            self.close()
        else:
            # Accept the connection
            user = self.scope['user']
            self.group_name = f'noti_{user.userID}'
            async_to_sync(self.channel_layer.group_add(self.group_name, self.channel_name))
            print(f"---- {user.username} with a userID of {user.userID} is in the group {self.group_name}.")
            self.accept()
    

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 29, 2025, 11:46pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/15 "2025-01-29T23:46:13Z")

</div>

Please post the complete log from the entire test.

---

<div class="post-metadata">

**Author:** ![B4sic101](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/b4sic101/32/25566_2.png) [@B4sic101](https://forum.djangoproject.com/u/B4sic101)\
**Post date:** [January 29, 2025, 11:47pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/16 "2025-01-29T23:47:02Z")

</div>

Just GET requests:

```auto
WebSocket HANDSHAKING /ws/notifyFR/ [127.0.0.1:53960]
---- Jerry Kole with a userID of 3f1e0afe-64ac-4ce4-b5e3-dd5cb4b4555e is in the group noti_3f1e0afe-64ac-4ce4-b5e3-dd5cb4b4555e.
WebSocket CONNECT /ws/notifyFR/ [127.0.0.1:53960]
WebSocket DISCONNECT /ws/notifyFR/ [127.0.0.1:48290]
HTTP GET /dashboard/ 200 [0.01, 127.0.0.1:44088]
HTTP GET /static/dashboard/main/main.css 200 [0.00, 127.0.0.1:44088]
HTTP GET /static/dashboard/main/main.js 200 [0.00, 127.0.0.1:44100]
HTTP GET /static/dummyUser.png 200 [0.00, 127.0.0.1:44100]
HTTP GET /uploads/profiles/user_16bb0918-aa22-44e3-8864-8b639a915190.jpeg 200 [0.01, 127.0.0.1:44088]
WebSocket HANDSHAKING /ws/notifyFR/ [127.0.0.1:44112]
---- Frank with a userID of 16bb0918-aa22-44e3-8864-8b639a915190 is in the group noti_16bb0918-aa22-44e3-8864-8b639a915190.
WebSocket CONNECT /ws/notifyFR/ [127.0.0.1:44112]

```

The initial disconnect is the app resetting.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 29, 2025, 11:48pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/17 "2025-01-29T23:48:56Z")

</div>

This output doesn’t include the other information shown earlier.

Please post the complete log from the entire test.

---

<div class="post-metadata">

**Author:** ![B4sic101](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/b4sic101/32/25566_2.png) [@B4sic101](https://forum.djangoproject.com/u/B4sic101)\
**Post date:** [January 29, 2025, 11:51pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/18 "2025-01-29T23:51:15Z")

</div>

I don’t understand, the outputs are the same with a difference of the requests in-between. I am only showing the WebSockets establishing connections. Do you want the web server starting up included aswell?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 29, 2025, 11:52pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/19 "2025-01-29T23:52:12Z")

</div>

Please post the complete log from the entire test.

---

<div class="post-metadata">

**Author:** ![B4sic101](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/b4sic101/32/25566_2.png) [@B4sic101](https://forum.djangoproject.com/u/B4sic101)\
**Post date:** [January 29, 2025, 11:53pm UTC](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367/20 "2025-01-29T23:53:21Z")

</div>

Alright, completely unfiltered:

```auto
***apps.py loaded***
 ***signals.py loaded***
Watching for file changes with StatReloader
Performing system checks...

***forms.py loaded***
System check identified no issues (0 silenced).
January 29, 2025 - 23:43:11
Django version 5.1.4, using settings 'app_dependencies.settings'
Starting ASGI/Daphne version 4.1.2 development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
HTTP GET /dashboard/ 200 [0.01, 127.0.0.1:48264]
WebSocket HANDSHAKING /ws/notifyFR/ [127.0.0.1:48266]
---- Jerry Kole with a userID of 3f1e0afe-64ac-4ce4-b5e3-dd5cb4b4555e is in the group noti_3f1e0afe-64ac-4ce4-b5e3-dd5cb4b4555e.
WebSocket CONNECT /ws/notifyFR/ [127.0.0.1:48266]
HTTP GET /dashboard/ 200 [0.01, 127.0.0.1:48274]
WebSocket HANDSHAKING /ws/notifyFR/ [127.0.0.1:48290]
---- Frank with a userID of 16bb0918-aa22-44e3-8864-8b639a915190 is in the group noti_16bb0918-aa22-44e3-8864-8b639a915190.
WebSocket CONNECT /ws/notifyFR/ [127.0.0.1:48290]
WebSocket DISCONNECT /ws/notifyFR/ [127.0.0.1:48266]
HTTP GET /dashboard/ 200 [0.03, 127.0.0.1:48264]
WebSocket HANDSHAKING /ws/notifyFR/ [127.0.0.1:53940]
---- Jerry Kole with a userID of 3f1e0afe-64ac-4ce4-b5e3-dd5cb4b4555e is in the group noti_3f1e0afe-64ac-4ce4-b5e3-dd5cb4b4555e.
WebSocket CONNECT /ws/notifyFR/ [127.0.0.1:53940]
WebSocket DISCONNECT /ws/notifyFR/ [127.0.0.1:53940]
HTTP GET /dashboard/ 200 [0.01, 127.0.0.1:53942]
HTTP GET /static/dashboard/main/main.css 200 [0.00, 127.0.0.1:53942]
HTTP GET /static/dashboard/main/main.js 200 [0.00, 127.0.0.1:53952]
HTTP GET /static/dummyUser.png 200 [0.00, 127.0.0.1:53942]
HTTP GET /uploads/profiles/user_3f1e0afe-64ac-4ce4-b5e3-dd5cb4b4555e.jpeg 200 [0.01, 127.0.0.1:53952]
WebSocket HANDSHAKING /ws/notifyFR/ [127.0.0.1:53960]
---- Jerry Kole with a userID of 3f1e0afe-64ac-4ce4-b5e3-dd5cb4b4555e is in the group noti_3f1e0afe-64ac-4ce4-b5e3-dd5cb4b4555e.
WebSocket CONNECT /ws/notifyFR/ [127.0.0.1:53960]
WebSocket DISCONNECT /ws/notifyFR/ [127.0.0.1:48290]
HTTP GET /dashboard/ 200 [0.01, 127.0.0.1:44088]
HTTP GET /static/dashboard/main/main.css 200 [0.00, 127.0.0.1:44088]
HTTP GET /static/dashboard/main/main.js 200 [0.00, 127.0.0.1:44100]
HTTP GET /static/dummyUser.png 200 [0.00, 127.0.0.1:44100]
HTTP GET /uploads/profiles/user_16bb0918-aa22-44e3-8864-8b639a915190.jpeg 200 [0.01, 127.0.0.1:44088]
WebSocket HANDSHAKING /ws/notifyFR/ [127.0.0.1:44112]
---- Frank with a userID of 16bb0918-aa22-44e3-8864-8b639a915190 is in the group noti_16bb0918-aa22-44e3-8864-8b639a915190.
WebSocket CONNECT /ws/notifyFR/ [127.0.0.1:44112]

```

[Next page](https://forum.djangoproject.com/t/group-send-fired-but-consumer-is-not-receiving/38367.md?page=2)
