Reputation: 186
Getting null object in SQS lambda when I push the object in SQS through java code.
I am pushing order number when an order is created to SQS.
server logs prints following: 2019-01-29 23:22:13 [threadPoolTaskExecutor-1] DEBUG c.a.s.sqs.MessageMD5ChecksumHandler - Message body: {"orderNumber":"201901292322090"}
but when I pull it through lambda. I am getting null in order number Input: Order [orderNumber=null] (tostring of the object) in AWS lambda code.
I do not understand how ordernumber is not translated properly.
SQS push code:
SendMessageRequest send_msg_request = .... .withMessageBody(objectMapper.writeValueAsString(order)) ...
Aws lambda:
public class BookingSQSHandler implements RequestHandler< Order , String > {
public String handleRequest(final Order order, final Context context) {
context.getLogger().log("Input: " + order);
// send email and return
}
getting null order nnumber in aws lambda function.
polled message from SQS, it is fine there but not sure what is happening with Lambda.
Upvotes: 0
Views: 1740
Reputation: 551
The RequestHandler needs to handle an SQSEvent, and not an Order in your example. From the SQS docs:
package example;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.SQSEvent;
import com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;
public class Handler implements RequestHandler<SQSEvent, Void>{
@Override
public Void handleRequest(SQSEvent event, Context context)
{
for(SQSMessage msg : event.getRecords()){
System.out.println(new String(msg.getBody()));
}
return null;
}
}
Your actual payload is the JSOn string of the message body.
Upvotes: 0
Reputation: 61
What's the structure and content of your Order
class?
It's possible that the orderNumber
property can't be mapped to methods or properties in the Order
class. You might need to make some changes in the Order
class itself, for example implementing a setter or ensuring you have appropriate constructors.
Upvotes: 1