How do I send and receive a Java Object from SQS? For instance, I have a java object Log. I send the object to the message queue as
this.getSqs().sendMessage(new SendMessageRequest(myQueueUrl, log.toString());
However, at the time of retrieving the message from queue, I want to be able to retrieve it as List<Log>
and use it as a java Log object inside my application. Any pointers on how to do that?
Id use Gson to serialize and deserialize pojo's to strings
you would send the message above as
sendMessage(new SendMessageRequest(myQueueUrl,log.toString());
then when you get a List<Messages> messages = sns.read();
for(Message m:messages){
String json= m.getBody();
Gson g = new Gson();
Log l = g.fromJson(json,Log.class);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With