Skip to content

Instantly share code, notes, and snippets.

@hamsolodev
Created June 24, 2010 07:23
Show Gist options
  • Save hamsolodev/451109 to your computer and use it in GitHub Desktop.
Save hamsolodev/451109 to your computer and use it in GitHub Desktop.
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="sendemail",
exchange="sendemail",
routing_key="sendemail_emails")
logger.info("sending emails...")
for message in consumer.iterqueue():
logger.info("boo")
logger.info(message.payload.get('email'))
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment