> I want to build an app that consume some zmq message and put them in django 
> model, django app has others functions.
> 
> I don't how can i mix zmq ioloop and django loop.
> 
> Is there an easy solution ?
> 

I do this. Just write a Django management command which never finishes. Here's 
some code off the top of my head, not tested at all:

import json
import zmq
from django.core.management.base import NoArgsCommand
from django import transaction
from myapp.models import SomeModel

class Command(NoArgsCommand):

  def handle_noargs(self, **options):
    c = zmq.Context()
    s = c.socket(zmq.PULL)
    s.connect('tcp://127.0.0,1:5000')
    try:
      while True:
        self.process_message(s.recv())
    finally:
      s.close()
      c.term()

  @transaction.commit_on_success
  def process_message(self, message):
    m = json.loads(message)
    SomeModel.objects.create(title=m['title'])


That would live in (for example) myapp/management/commands.

Cheers,
Dan

--
Dan Fairs | [email protected] | www.fezconsulting.com

_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to