本文整理汇总了Python中boto.sqs.message.RawMessage.set_body方法的典型用法代码示例。如果您正苦于以下问题:Python RawMessage.set_body方法的具体用法?Python RawMessage.set_body怎么用?Python RawMessage.set_body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto.sqs.message.RawMessage
的用法示例。
在下文中一共展示了RawMessage.set_body方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: enqueueNotification
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def enqueueNotification(phoneNumber, name, messageType = 'text'):
config = configparser.RawConfigParser()
config.read(os.path.join(os.getcwd() + '/django_drf_starter_project/scripts/','settings.cfg'))
region = config.get('AWS', 'region')
queueName = config.get('AWS', 'queue')
accessKey = config.get('AWS', 'accessKey')
secretKey = config.get('AWS', 'secretKey')
pprint(accessKey)
pprint(secretKey)
conn = boto.sqs.connect_to_region(region,aws_access_key_id=accessKey,aws_secret_access_key=secretKey) ##change before final
q = conn.create_queue(queueName) #10-second message visibility
if len(phoneNumber) > 10:
phoneNumberNoCountryCode = phoneNumber[1:]
else:
phoneNumberNoCountryCode = phoneNumber
data = {
'phoneNumber': str(phoneNumberNoCountryCode),
'name': str(name),
'type': str(messageType)
}
m = RawMessage()
m.set_body(json.dumps(data))
q.write(m)
示例2: connectAndWriteToSQS
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def connectAndWriteToSQS(queue, data):
sqs = boto.connect_sqs()
sqs = boto.sqs.connect_to_region('us-west-1')
q = sqs.create_queue(queue)
m = RawMessage()
m.set_body(json.dumps(data))
q.write(m)
示例3: append_to_queue
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def append_to_queue(content, queue, raw=False):
'''Queues a message to SQS with a specific message'''
body = json.dumps(content)
m = RawMessage() if raw else Message()
m.set_body(body)
receipt = queue.write(m)
return receipt
示例4: ApprovalProcess
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def ApprovalProcess(msg):
data = dict()
# The messages received from the imageresult queue
# ???? format ??? str or int
data['imagekey'] = str(msg['imagekey'])
data['imageheight'] = str(msg['imageheight'])
data['imagewidth'] = str(msg['imagewidth'])
# retrive rest data from simpleDB
domain = _getImageDomain()
item = domain.get_item(msg['imagekey'])
data['imageURL'] = item['imageurl']
data['tag'] = item['tag']
data['description'] = item['description']
data['submituser'] = item['submituser']
data['submitdate'] = item['submitdate']
# Connect to SQS and create the approval process queue
sqs = boto.connect_sqs(AWSKey, AWSSecret)
q = sqs.create_queue(approvalprocessQueue)
# Put the message in the queue
# m is raw message object
# queue only accept message object
m = RawMessage()
m.set_body(json.dumps(data))
# add comment to Queue
status = q.write(m)
示例5: run
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def run():
conn = boto.sqs.connect_to_region("us-west-2")
requestQueue = conn.get_queue('GredientRequest')
requestQueue.set_message_class(RawMessage)
while (True):
rs = requestQueue.get_messages(1)
if (len(rs) != 0):
m = rs[0]
body = m.get_body()
foodName = body.split('_')[0]
requestQueue.delete_message(m)
here = body.split('_')[1]
responseQueue = conn.get_queue(body.split('_')[2])
if responseQueue is not None:
responseQueue.set_message_class(RawMessage)
response = RawMessage()
markets = database.getMarkets(foodName)
if len(markets) == 0:
response.set_body(foodName+" is not found in our database!!")
else:
nearest = getNearestMarket(here, markets)
name = nearest['Name']
address = nearest['Address']
dis = nearest['Distance']
response.set_body(foodName+" @ "+name+" @ "+address + " @ "+ dis)
responseQueue.write(response)
示例6: WriteToWriteQueue
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def WriteToWriteQueue(self, action, endpoint, body, headers, message_id, output_queue):
writeQ = self.conn.get_queue(str(output_queue))
m = RawMessage()
response =''
if (action == 'GET'):
response = requests.get(endpoint, headers=headers)
elif (action == 'PUT'):
response = requests.put(endpoint, data = json.dumps(body), headers=headers)
elif(action == 'POST'):
response = requests.post(endpoint, data = json.dumps(body), headers=headers)
elif (action == 'DELETE'):
response = requests.delete(endpoint, headers=headers)
print response.text
response_final = {
'messageId': str(message_id),
'response': str(response.text)
}
m.set_body(json.dumps(response_final))
writeQ.write(m)
示例7: queue
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def queue(request, queue_name):
conn = connector()
queue = conn.get_all_queues(prefix=queue_name)[0]
if request.POST:
if '_clear' in request.POST:
queue.clear()
return redirect('/sqs/queues/' + queue_name)
# will have to wait for s3 integration
#if '_dump' in request.POST:
# queue.save_to_s3('sqs_dump')
elif '_delete' in request.POST:
queue.delete()
return redirect('/sqs/queues/')
form = AddMessageForm(request.POST)
if form.is_valid():
m = RawMessage()
m.set_body(form.cleaned_data['message'])
count = form.cleaned_data['count']
while count:
queue.write(m)
count -= 1
return redirect('/sqs/queues/' + queue_name)
else:
form = AddMessageForm()
item = queue.get_attributes()
item['name'] = queue.name
return render(request, 'sqs/queue.html', {
'queue': item,
'form': form,
})
示例8: emit
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def emit(self, record):
if isinstance(record.args, dict):
record.customer = record.args['customer']
else:
record.customer = 'Sender'
#formatted_record = self.format(record)
ct = '%Y/%m/%d %H:%M:%S'
dtime = datetime.datetime.utcfromtimestamp(record.created)
data = {}
data['levelname'] = record.levelname
data['asctime'] = dtime.strftime(ct)
data['customer'] = record.customer
data['message'] = record.msg
data['name'] = record.name
data['funcName'] = record.funcName
data['filename'] = record.filename
data['@timestamp'] = datetime.datetime.strptime(data['asctime'], '%Y/%m/%d %H:%M:%S').strftime('%Y-%m-%dT%H:%M:%SZ')
msg = {}
msg['_id'] = str(uuid.uuid4())
msg['_index'] = "sqs-river-" + datetime.datetime.now().strftime("%Y.%m")
msg['_type'] = "mailexpress"
msg['_data'] = data
#print json.dumps(msg)
m = RawMessage()
m.set_body(json.dumps(msg))
self.q.write(m)
示例9: commentsubmit
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def commentsubmit(req):
sdb = boto.connect_sdb(AWSKey, AWSSecret)
domain = sdb.get_domain('comment')
form = req.form
imagekey = form['imagekey']
user = form['commentuser']
cmt = form['comment']
import uuid
from time import strftime
guid = str(uuid.uuid1())
item = domain.new_item(guid)
item['submituser'] = user
item['imagekey'] = imagekey
item['comment'] = cmt
item['status'] = "processing"
item['submitdate'] = strftime("%Y-%m-%dT%H:%M:%S")
item.save()
sqsconn = SQSConnection(AWSKey, AWSSecret)
q = sqsconn.get_queue('commentprocess')
request = {}
request['commentkey'] = guid
request['submitdate'] = strftime("%Y-%m-%dT%H:%M:%S")
request['comment'] = str(cmt)
request['submituser'] = str(user)
m = RawMessage()
m.set_body(json.write(request))
status = q.write(m)
response = {}
if status==m:
response['complete'] = True
response['commentkey'] = guid
else:
response['complete'] = False
return json.write(response)
示例10: sendMessageToInputQueue
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def sendMessageToInputQueue(q, anim_name,frame_file,type,userid):
# Data required by the API
if type == 'Frame':
data = {
'msgtype': str(type),
'submitdate': time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime()),
'key': str(uuid.uuid1()),#secret key/anwer to s3 instead of boto config file
'userid': str(userid), #or bucketname attribute
'anim_name':str(anim_name),
'frame_file': str(frame_file)
}
elif type == 'killCommand':
data = {
'msgtype': str(type),
'submitdate': time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime()),
'key': str(uuid.uuid1()),#secret key/anwer to s3 instead of boto config file
'userid': str(userid), #or bucketname attribute
'command': str(message)
}
# Connect to SQS and open the queue
# Put the message in the queue
m = RawMessage()
m.set_body(json.dumps(data))
status = q.write(m)
示例11: write_to_que
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def write_to_que(data):
conn = boto.sqs.connect_to_region("us-east-1")
my_queue = conn.get_queue('email_queue')
# Put the message in the queue
m = RawMessage()
m.set_body(json.dumps(data))
status = my_queue.write(m)
示例12: write_data
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def write_data(self, input_data):
'''
Writes a data to the queue created, or publishes the data via a topic to the queues
:param input_data: Data to be written to the queue, published to queues via a topic
'''
producer_data = json.dumps(input_data)
matcher = json.loads(producer_data)
if matcher[0]['meta-inf'] == "content":
if self.topic_name is not None:
print("Publishing the data to the topic object")
publication = self.sns_conn.publish(self.sns_topic_arn,producer_data)
else:
print("Writing the data to the queue")
queue_data = RawMessage()
queue_data.set_body(json.dumps(input_data))
# Writing the data to the queue
self.queue_object.write(queue_data)
elif matcher[0]['meta-inf'] == "meta":
# S3 content goes here
raw_data = matcher[1]['data']
file_key = os.path.split(raw_data)[-1]
self.s3object.upload(file_key,raw_data)
if self.topic_name is not None:
print("Publishing the data to the topic object")
publication = self.sns_conn.publish(self.sns_topic_arn,producer_data)
else:
print("Writing the data to the queue")
queue_data = RawMessage()
queue_data.set_body(json.dumps(input_data))
# Writing the data to the queue
self.queue_object.write(queue_data)
示例13: write_msg
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def write_msg(self, queue, msg):
""" Write SQS message as JSON. """
m = RawMessage()
m.set_body(base64.b64encode(json.dumps(msg)))
q = self.conn.lookup(queue)
msg_sent = q.write(m)
print("Sent Msg; queue={0}, msg={1.id}".format(queue, msg_sent))
return msg_sent
示例14: setSQS
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def setSQS(data, queue):
# Put the message in the queue
# m is raw message object
# queue only accept message object
m = RawMessage()
m.set_body(json.dumps(data))
# add comment to Queue
status = queue.write(m)
示例15: to_queue
# 需要导入模块: from boto.sqs.message import RawMessage [as 别名]
# 或者: from boto.sqs.message.RawMessage import set_body [as 别名]
def to_queue(obj, queue_name):
if environment.local:
print('[queue] {}'.format(queue_name))
else:
queue = sqs.get_queue(queue_name)
message = RawMessage()
message.set_body(json.dumps(obj))
queue.write(message)