Example #1
0
    def consume_messages(self, sqsQueueName=QUEUE_NAME):
        num_msgs = 0
        try:
            queue = self.get_queue()
            if queue:
                mesgs = get_messages(queue)
                if not len(mesgs):
                    print("There are no messages in Queue to display")
                    return num_msgs
                for mesg in mesgs:
                    attributes = get_attributes(mesg)
                    sender_id = attributes.get('SenderId')
                    sent_timestamp = attributes.get('SentTimestamp')

                    bd = mesg.body
                    order_dict = eval(bd)
                    porder = utils.Order(order_dict)
                    # Adds message metadata to Order object.
                    porder.set_sender_id(sender_id)
                    porder.set_sent_timestamp(sent_timestamp)
                    print(porder)

                    self.delete_message(queue, mesg)
                    time.sleep(1)
                num_msgs = len(mesgs)
        except Exception as err:
            print("Error Message {0}".format(err))
        return num_msgs
def publish_order_msgs(topicArn=TOPIC_ARN_ORDER, orderDetails=ORDER_DETAILS):
    sns = boto3.resource('sns')
    for i in range(1, utils.NUM_MESSAGES + 1):
        orderDict = {
            'orderId': i,
            'orderDate': "2015/10/%d" % i,
            'orderDetails': orderDetails}
        porder = utils.Order(orderDict)
        print("Publishing order to SNS topic:", repr(porder))
        jsonStr = convert_order_to_json(porder)
        publish_order(sns, topicArn, jsonStr)
        print("Order topic published")
Example #3
0
def publish_order_msgs(topicArn=TOPIC_ARN_ORDER, orderDetails=ORDER_DETAILS):
    sns_client = session.client('sns')
    for i in range(1, utils.NUM_MESSAGES + 1):
        orderDict = {
            'orderId': i,
            'orderDate': "2015/10/%d" % i,
            'orderDetails': orderDetails}
        porder = utils.Order(orderDict)
        print("Publishing order to SNS topic:", repr(porder))
        jsonStr = json.dumps(porder, default=utils.jdefault, indent=4)  # convert_order_to_json(porder)
        publish_order(sns_client, topicArn, jsonStr)
        print("Order topic published")