How to configure zeromq using django

I am working on zeromq PUB / SUB and I have configured zeromq PUB on django.

This is my code that I use to configure zeromq

from gevent_zeromq import zmq

I am using the gevent_zeromq library

@api_view(['POST','GET'])
def NOTIFICATION(request):
if request.method == 'GET':
    return render_to_response('notifications.html',context)
if request.method == 'POST':
    message_json = json.dumps(request.data)
    message_load = json.loads(message_json)
    message = {message_load['msg']}
    ctx = zmq.Context()
    publisher = ctx.socket(zmq.PUB)
    publisher.bind("tcp://*:5566")
    time.sleep(1)
    while True:
        publisher.send_multipart("message:%s" % str(message))
        time.sleep(1)
    publisher.close()
    ctx.term() 
return Response('',status=200)

I am using ajax / jquery to access web resources.

This code works, but when I send another message from the interface, it gives me an error:

 File "/home/admin/dx_man/dx_man/views.py", line 42, in NOTIFICATION
    publisher.bind("tcp://*:5566")
    File "socket.pyx", line 447, in zmq.core.socket.Socket.bind (zmq/core/socket.c:4312)
    ZMQError: Address already in use

How can I do this with ajax, django.zeromq.

I want to make only the publisher, the subscriber will be divided, so as soon as the publisher publishes the message later, the subscriber will process it, but here I ran into a problem.

Can someone give me a better solution for this so that I can process all messages from the web interface, and I also want to store the messages in the database, which I will process after posting the message.

+4
1

ZMQ , - , , .

:

  • ( , Python , )
  • time.sleep(1),
  • ZMQ_LINGER , , , ... , , .
  • , , , , , connect() PUB bind() SUB.

, PUB , SUB- , SUB- "" bind().

+4

All Articles