elastic-coders / pushpull

Websocket to rabbitmq gateway
MIT License
3 stars 3 forks source link

Docs on where the messages are forwarded are unclean #9

Open vporton opened 6 years ago

vporton commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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.