Skip to content

Docs on where the messages are forwarded are unclean #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vporton opened this issue Sep 28, 2017 · 2 comments
Open

Docs on where the messages are forwarded are unclean #9

vporton opened this issue Sep 28, 2017 · 2 comments

Comments

@vporton
Copy link
Contributor

vporton commented Sep 28, 2017

How is it determined to which WebSockets a message send to RabbitMQ is delivered?

Reversely, how is it determined to which channels (or what?) of RabbitMQ a frame delivered through WebSocket is delivered?

Docs are silent on this important issue. Please note that your software is largely useless without proper documentation.

I have created the following authenticator:

import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "XXX.settings")
# settings.configure()
django.setup()

from django.contrib.sessions.models import Session
from core_app.models import User


def main():
    return authenticate


# Why async?
async def authenticate(token):
    try:
        session = Session.objects.get(pk=token)
    except Session.DoesNotExist:
        return None
    try:
        user_id = session.get_decoded()['user_id']
        user = User.objects.get(pk=user_id)
        return user_id, user.email
    except:
        return None

I run it as:

pushpull-client authenticate_amqp amqp://localhost/ ws_app.django_session:main

In my JavaScript code I pass the Django Session ID in http-authorization URL parameter of the ws:// connection.

And after this I do not receive WS messages in my JavaScript code.

Before writing and testing this my code I thought that I pass the Session ID as http-authorization URL parameter, my auth code converts it to Django user ID and this user ID can be used as the user ID for RabbitMQ. In some reason this does not work. It seems I misunderstand something.

I also use:

class TestClick(View):
    def post(self, request):
        connection = pika.BlockingConnection()
        channel = connection.channel()
        channel.basic_publish(exchange='pushpull.rpc',
                              routing_key='pushpull.rpc',
                              body='{"test": "Test"}')
        connection.close()

        return HttpResponse('')

Now my problem:

I need to communicate with a WebSocket client identified by a secret hash (such as Django Session ID). I do not understand how to send a message to only one user (that one which we have Session ID of).

I thought that Session ID is the user_token (as in your docs) and User ID can be used as user_id (as in your docs).

Also: How to send a message to a particular WS user using pika Python library?

@mpaolini
Copy link
Member

Please note that your software is largely useless without proper documentation.

This is an open source library written in my own spare time, it's marked as beta and of unfortunately it lacks proper documentation.

You can just have a look at the code, as the library is very small to figure out things.

You are welcome to contribute opening pull requests to improve the docs

@vporton
Copy link
Contributor Author

vporton commented Sep 29, 2017

The issue is solved by using pika in the way described at https://github.com/vporton/pushpull

In some reason I cannot create a pull request (there is no "Create pull request" button) for this documentation change. Maybe I need to wait when my previous pull request is accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants