#!/usr/bin/env python
"""
    Just sends a JSON message to the last created SQS queue

    @author: Jean-Lou Dupont
"""
import os, sys
op=os.path

try:
    if os.environ.get("DEVMODE", False):
        raise
    import jldaws #@UnusedImport
except:
    ### must be in dev mode then    
    this_dir=op.dirname(__file__)
    lib_path=op.abspath(op.join(this_dir, ".."))
    sys.path.insert(0, lib_path)
    import jldaws #@UnusedImport

########################################################################

import boto
from boto.sqs.jsonmessage import JSONMessage

conn = boto.connect_sqs()  
queues=conn.get_all_queues()

queue_id=queues[-1].id
queue_name=queues[-1].name

print "! writing to queue: %s" % queue_id

q=conn.create_queue(queue_name)

q.set_message_class(JSONMessage) 

msg=JSONMessage()
msg["subject"]="test"

q.write(msg)

