@Override public String topicFor(MessageWithDestination messageWithDestination) { return messageWithDestination.getDestination(); }
@Override public String partitionKeyFor(MessageWithDestination messageWithDestination) { String id = messageWithDestination.getMessage().getId(); return messageWithDestination.getMessage().getHeader(Message.PARTITION_ID).orElse(id); }
@Override public List<MessageWithDestination> parse(PostgresWalMessage message, long lastSequenceNumber, String slotName) { List<PostgresWalChange> changes = Arrays.asList(message.getChange()); return changes .stream() .filter(change -> change.getKind().equals("insert") && change.getTable().equals("message")) .map(insertedEvent -> { List<String> columns = Arrays.asList(insertedEvent.getColumnnames()); List<String> values = Arrays.asList(insertedEvent.getColumnvalues()); int destination = columns.indexOf("destination"); int payload = columns.indexOf("payload"); int headers = columns.indexOf("headers"); return new MessageWithDestination(values.get(destination), new MessageImpl(values.get(payload), JSonMapper.fromJson(values.get(headers), Map.class)), new BinlogFileOffset(slotName, lastSequenceNumber)); }) .collect(Collectors.toList()); } }
@Override public List<MessageWithDestination> parse(PostgresWalMessage message, long lastSequenceNumber, String slotName) { List<PostgresWalChange> changes = Arrays.asList(message.getChange()); return changes .stream() .filter(change -> change.getKind().equals("insert") && change.getTable().equals("message")) .map(insertedEvent -> { List<String> columns = Arrays.asList(insertedEvent.getColumnnames()); List<String> values = Arrays.asList(insertedEvent.getColumnvalues()); int destination = columns.indexOf("destination"); int payload = columns.indexOf("payload"); int headers = columns.indexOf("headers"); return new MessageWithDestination(values.get(destination), new MessageImpl(values.get(payload), JSonMapper.fromJson(values.get(headers), Map.class)), new BinlogFileOffset(slotName, lastSequenceNumber)); }) .collect(Collectors.toList()); } }
@Override public MessageWithDestination parseEventData(WriteRowsEventData eventData, String binlogFilename, long position) throws IOException { if (columnOrders.isEmpty()) { try { getColumnOrders(); } catch (SQLException e) { logger.error("Error getting metadata", e); throw new RuntimeException(e); } } String id = (String)getValue(eventData, ID); String destination = (String)getValue(eventData, DESTINATION); String payload = (String)getValue(eventData, PAYLOAD); Map<String, String> headers = JSonMapper.fromJson((String)getValue(eventData, HEADERS), Map.class); headers.put(Message.ID, id); headers.put("binlogfile", binlogFilename); headers.put("binlogposition", Long.toString(position)); return new MessageWithDestination(destination, new MessageImpl(payload, headers), new BinlogFileOffset(binlogFilename, position)); }
@Override public String getId(MessageWithDestination messageWithDestination) { return messageWithDestination.getMessage().getId(); }
@Override public String topicFor(MessageWithDestination messageWithDestination) { return messageWithDestination.getDestination(); }
@Override public MessageWithDestination parseEventData(WriteRowsEventData eventData, String binlogFilename, long position) throws IOException { if (columnOrders.isEmpty()) { try { getColumnOrders(); } catch (SQLException e) { logger.error("Error getting metadata", e); throw new RuntimeException(e); } } String id = (String)getValue(eventData, ID); String destination = (String)getValue(eventData, DESTINATION); String payload = (String)getValue(eventData, PAYLOAD); Map<String, String> headers = JSonMapper.fromJson((String)getValue(eventData, HEADERS), Map.class); headers.put(Message.ID, id); headers.put("binlogfile", binlogFilename); headers.put("binlogposition", Long.toString(position)); return new MessageWithDestination(destination, new MessageImpl(payload, headers), new BinlogFileOffset(binlogFilename, position)); }
@Override public String partitionKeyFor(MessageWithDestination messageWithDestination) { String id = messageWithDestination.getMessage().getId(); return messageWithDestination.getMessage().getHeader(Message.PARTITION_ID).orElse(id); }
@Override public MessageWithDestination transformEventBeanToEvent(PollingMessageBean pollingMessageBean) { Map<String, String> headers = JSonMapper.fromJson(pollingMessageBean.getHeaders(), Map.class); return new MessageWithDestination(pollingMessageBean.getDestination(), new MessageImpl(pollingMessageBean.getPayload(), headers), null); } }
@Override public String toJson(MessageWithDestination messageWithDestination) { return JSonMapper.toJson(messageWithDestination.getMessage()); }
@Override public MessageWithDestination transformEventBeanToEvent(PollingMessageBean pollingMessageBean) { Map<String, String> headers = JSonMapper.fromJson(pollingMessageBean.getHeaders(), Map.class); return new MessageWithDestination(pollingMessageBean.getDestination(), new MessageImpl(pollingMessageBean.getPayload(), headers), null); } }
@Override public String getId(MessageWithDestination messageWithDestination) { return messageWithDestination.getMessage().getId(); }
@Override public String toJson(MessageWithDestination messageWithDestination) { return JSonMapper.toJson(messageWithDestination.getMessage()); }