Skip to content

Instantly share code, notes, and snippets.

@hamsolodev
Created June 24, 2010 07:23
Show Gist options
  • Select an option

  • Save hamsolodev/451109 to your computer and use it in GitHub Desktop.

Select an option

Save hamsolodev/451109 to your computer and use it in GitHub Desktop.

Revisions

  1. markhellewell renamed this gist Jun 24, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. markhellewell revised this gist Jun 24, 2010. 1 changed file with 22 additions and 0 deletions.
    22 changes: 22 additions & 0 deletions gistfile2.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    from carrot.connection import DjangoBrokerConnection
    from carrot.messaging import Publisher, Consumer
    connection = DjangoBrokerConnection()
    publisher = Publisher(connection=connection, exchange="sendemail", routing_key="sendemail_emails")
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.send({'email': '[email protected]'})
    publisher.close()
    connection.close()
  3. markhellewell revised this gist Jun 24, 2010. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gistfile1.pyw
    Original file line number Diff line number Diff line change
    @@ -16,9 +16,9 @@ then in my Celery Task:
    try:
    connection = DjangoBrokerConnection()
    consumer = Consumer(connection=connection,
    queue="senddrop",
    exchange="senddrop",
    routing_key="senddrop_emails")
    queue="sendemail",
    exchange="sendemail",
    routing_key="sendemail_emails")

    logger.info("sending emails...")
    for message in consumer.iterqueue():
  4. markhellewell created this gist Jun 24, 2010.
    26 changes: 26 additions & 0 deletions gistfile1.pyw
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    if request.method == "POST":
    email_form = SendAnEmail(request.POST, prefix='emailform')
    if email_form.is_valid():
    connection = DjangoBrokerConnection()
    publisher = Publisher(connection=connection,
    exchange="sendemail",
    routing_key="sendemail_emails")
    publisher.send(email_form.cleaned_data.get('email_address'))
    publisher.close()
    connection.close()


    then in my Celery Task:


    try:
    connection = DjangoBrokerConnection()
    consumer = Consumer(connection=connection,
    queue="senddrop",
    exchange="senddrop",
    routing_key="senddrop_emails")

    logger.info("sending emails...")
    for message in consumer.iterqueue():
    logger.info("boo")
    logger.info(message.payload.get('email'))