예제 #1
0
파일: server.py 프로젝트: YuriAR/Lab12and13
def write_message(name):
	conn = get_conn()
	m = Message()
	body = request.get_json(force=True)
	m.set_body(body["content"])
	queue = conn.get_queue(name)
	if queue is None:
                resp = json.dumps("Queue not found\n")
	else:
		queue.write(m)
		resp = json.dumps("Message written\n")
        return Response(response=resp,mimetype="application/json")
예제 #2
0
파일: server.py 프로젝트: TaOnAs/lab1213
def write_message(name):
    """
    Write a message
    curl -s -X POST -H 'Accept: application/json' http://localhost:5000/queues/<name>/msgs -d '{"content": "this is a message"}' | python -mjson.tool
    """
    body = request.get_json(force=True)
    content = body['content']
    
    queue = conn.get_queue(name)
    m = Message()
    m.set_body(content)
    queue.write(m)
    return Response(response='{"response": "Message %s written to queue"}' % content, mimetype="application/json")
예제 #3
0
def write_message(name):
    """
    Write a message

    curl -s -X POST -H 'Accept: application/json' http://localhost:5000/queues/<name>/msgs -d '{"content": "this is a message"}' | python -mjson.tool

    """
    body = request.get_json(force=True)
    content = body['content']
    queue = conn.get_queue(name)
    if(queue is not None):
        messageObj = Message()
        messageObj.set_body(content)
        queue.write(messageObj)
        resp = 'Message created\n'
    else:
        resp = 'Queue % was not found\n' % name 
    return Response(response=resp, mimetype="application/json")
예제 #4
0
def messages_write(name):
    """
	Write message to queue
	curl -s -X POST -H 'Accept: application/json' http://localhost:8080/queues/hello_world/msgs -d '{"content" : "this is a hello world queue"}'
	"""

    body = request.get_json(force=True)
    messageText = body['content']

    conn = get_conn()
    queue = conn.get_queue(name)
    queue.set_message_class(Message)
    m = Message()
    m.set_body(messageText)
    queue.write(m)

    resp = "Message " + messageText + " has been written to queue " + name + "\n"
    return Response(response=resp, mimetype="application/json")
예제 #5
0
def messages_write(name):
	"""
	Write message to queue
	curl -s -X POST -H 'Accept: application/json' http://localhost:8080/queues/hello_world/msgs -d '{"content" : "this is a hello world queue"}'
	"""

	body = request.get_json(force=True)
	messageText = body['content']

	conn = get_conn()
	queue = conn.get_queue(name)
	queue.set_message_class(Message)
	m = Message()
	m.set_body(messageText)
	queue.write(m)

	resp = "Message " + messageText + " has been written to queue "+ name +"\n"
	return Response(response=resp, mimetype="application/json")
예제 #6
0
def messages_write(name):
	"""
	Writee message to queue

	curl -s -X POST -H 'Accept: application/json' http://localhost:5000/queues/D15123353_Lab12/msgs -d '{"content": "this is the message I want to put on the queue"}' 
	curl -s -X POST -H 'Accept: application/json' 52.18.184.96:8080/queues/D15123353_Lab12/msgs -d '{"content": "this is the message I want to put on the queue"}'
	"""

	body = request.get_json(force=True)
	messageText = body['content']
	
	conn = get_conn()
	queue = conn.get_queue(name)
	queue.set_message_class(Message)
	m = Message()
	m.set_body(messageText)
	queue.write(m)
	
	resp = "Message "+messageText+" has been written to queue "+name+"\n"
	return Response(response=resp, mimetype="application/json")	
예제 #7
0
import sys
import requests

r = requests.get('http://ec2-52-30-7-5.eu-west-1.compute.amazonaws.com:81/key')
str = r.content.split(':',1)

queue_name = sys.argv[1]
message = sys.argv[2]



# Get the keys from a specific url and then use them to connect to AWS Service 
access_key_id = str[0]
secret_access_key = str[1]

# Set up a connection to the AWS service. 
conn = boto.sqs.connect_to_region("eu-west-1", aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key)

# delete a queue

m = Message()

m.set_body(message)

queue = conn.get_queue(queue_name)

queue.write(m)

print "Message " + message + " writen to queue " + queue_name

예제 #8
0
url = 'http://ec2-52-30-7-5.eu-west-1.compute.amazonaws.com:81/key'
req = urllib2.Request(url)
res = urllib2.urlopen(req)
key = res.read()
split = ':'
i = key.find(split)
word1 = key[:i]
word2 = key[i+len(split):]
res.close()

# Get the keys from a specific url and then use them to connect to AWS Service 
access_key_id = word1
secret_access_key = word2

# Set up a connection to the AWS service. 
conn = boto.sqs.connect_to_region("eu-west-1", aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key)

# Gets a queue and prints a message along side it 

q_name = sys.argv[1]

queue = conn.get_queue(q_name)

print "Message writing.."
queue.set_message_class(Message)
msg = Message()
msg.set_body(sys.argv[2])
queue.write(msg)
print "Done"
예제 #9
0
import os
import boto.sqs
import boto.sqs.queue
from boto.sqs.message import Message
from boto.sqs.connection import SQSConnection
from boto.exception import SQSError
import sys
import urllib2

response = urllib2.urlopen('http://ec2-52-30-7-5.eu-west-1.compute.amazonaws.com:81/key')
content = response.read();
content = content.split (':');
response.close();

# Get the keys from a specific url and then use them to connect to AWS Service 
access_key_id = str(content[0])
secret_access_key = str(content[1])

# Set up a connection to the AWS service. 
conn = boto.sqs.connect_to_region("eu-west-1", aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key)

# Write messege
queue = conn.get_queue(sys.argv[1])
message = Message()
message.set_body(sys.argv[2])
queue.write(message)