0

I am using boto library to read messages from SQS queue. My messages have text like this: { Command:XXXXXXXXXXX Key:XXXXXXX Input:XXXXXX} . Boto sends with base64 encoded and also reads it, so that if I read the message body then the text is there. But how can I read the message like

Command = input['Command'] Key = input_message['Key'].split(',') 

so that I can use those values for further processing...

I am quite new to Python also

0

2 Answers 2

1

Ok, you seem to have the input in some kind of a format - is it anything standardised? If not, you would need to parse the contents of your message and get the individual keys.

What I have been doing before in my projects was using JSON to facilitate data exchange between platforms.

If you do not have a luxury to edit your incoming data, you would need to do something like this (very naiive example):

input = "{ Command:XXXXXXXXXXX Key:XXXXXXX Input:XXXXXX }" data = filter(lambda x: ":" in x, input.split()) message_dict = dict() for item in data: key, val = item.split(":") message_dict[key] = val 
Sign up to request clarification or add additional context in comments.

Comments

0

Consider using good old fashioned JSON to easily send and receive dictionaries acrost the wire.

This test function verifies that the data format is very clear with JSON:

test_sqs.py

import json import boto3 from moto import mock_sqs @mock_sqs def test_sqs(): sqs = boto3.resource('sqs', 'us-east-1') queue = sqs.create_queue(QueueName='votes') queue.send_message(MessageBody=json.dumps( {'Command': 'drink', 'Key': 'beer', 'Input': 'tasty'})) messages = queue.receive_messages() assert len(messages) == 1 assert messages[0].body == ( '{"Input": "tasty", "Command": "drink", "Key": "beer"}') 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.