@Override
public List<MessageContainer> parse(String data) {
if (routingKey != null) {
return new ImmutableList.Builder<MessageContainer>()
.add(new DefaultMessageContainer(
new Message(routingKey, data.getBytes()),
jsonMapper))
.build();
} else {
try {
Map<String, Object> record = jsonMapper.readValue(data, S3Consumer.typeReference);
String routingKeyOnRecord = record.get(routingKeyField).toString();
if (Strings.isNullOrEmpty(routingKeyOnRecord)) {
routingKeyOnRecord = routingKey;
}
if (!Strings.isNullOrEmpty(routingKeyOnRecord)) {
return new ImmutableList.Builder<MessageContainer>()
.add(new DefaultMessageContainer(
new Message(routingKeyOnRecord, data.getBytes()),
jsonMapper))
.build();
} else {
return new ArrayList<MessageContainer>();