简体   繁体   中英

Unable to listen the SQS messages in java SqsListener produced from the python using boto SDK

I am sending the message using the boto SDK to Amazon-SQS. Whatever the message I send it has to listen using the SqsListener written in java.When I send message I am not able to get the exact message what I have send from the producer class written in python. In SQSListener class I just tried to print the message what I have got. I am getting the encrypted form of message instead of actual message.

Actual message: Sample message

Received Message U2FtcGxlIG1lc3NhZ2U=

The producer class written in the python is:

from boto import sqs
import json
from boto.sqs.message import Message 

conn = sqs.connect_to_region('XXXXX', aws_access_key_id='XXXXXXXXXXXX', aws_secret_access_key='XXXXXXXXXXXXXXXXXXXXXXX')
queueInstance = conn.get_queue('sample')
try:
   message = Message()    
   message.set_body("testing sample")
   queueInstance.write(message)
except Exception, error:
   print error

The Receiver SQSListener class is:

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;


public class SQSMessageLisner implements MessageListener {

public void onMessage(Message message) {
    try {
        System.out.println("Inside ON MESSAGE");
        //System.out.println(message.get);
        String stringMessage = ((TextMessage) message).getText();
        System.out.println(stringMessage);
    } catch (JMSException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
}

The sending the receiving of messages are written in same SDK's are working fine. Coming to sending from python and listening in java leads to this problem. Please help me out of this. Thanks in advance.

You get a base64 encoded message in your receiver. You need to decode it, as described here Decode Base64 data in Java

Your other option is to use boto.sqs.message.RawMessage in python instead of TextMessage, which will not be encoded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM