use of io.openmessaging.connector.api.data.SinkDataEntry in project rocketmq-externals by apache.
the class JdbcSinkTask method put.
@Override
public void put(Collection<SinkDataEntry> sinkDataEntries) {
try {
if (tableQueue.size() > 1) {
updater = tableQueue.poll(1000, TimeUnit.MILLISECONDS);
} else {
updater = tableQueue.peek();
}
for (SinkDataEntry record : sinkDataEntries) {
Map<Field, Object[]> fieldMap = new HashMap<>();
Object[] payloads = record.getPayload();
Schema schema = record.getSchema();
EntryType entryType = record.getEntryType();
String tableName = schema.getName();
String dbName = schema.getDataSource();
List<Field> fields = schema.getFields();
Boolean parseError = false;
if (!fields.isEmpty()) {
for (Field field : fields) {
Object fieldValue = payloads[field.getIndex()];
Object[] value = JSONObject.parseArray((String) fieldValue).toArray();
if (value.length == 2) {
fieldMap.put(field, value);
} else {
log.error("parseArray error, fieldValue:{}", fieldValue);
parseError = true;
}
}
}
if (!parseError) {
Boolean isSuccess = updater.push(dbName, tableName, fieldMap, entryType);
if (!isSuccess) {
log.error("push data error, dbName:{}, tableName:{}, entryType:{}, fieldMap:{}", dbName, tableName, fieldMap, entryType);
}
}
}
} catch (Exception e) {
log.error("put sinkDataEntries error, {}", e);
}
}
use of io.openmessaging.connector.api.data.SinkDataEntry in project rocketmq-externals by apache.
the class WorkerDirectTask method sendRecord.
private void sendRecord(Collection<SourceDataEntry> sourceDataEntries) {
List<SinkDataEntry> sinkDataEntries = new ArrayList<>(sourceDataEntries.size());
ByteBuffer position = null;
ByteBuffer partition = null;
for (SourceDataEntry sourceDataEntry : sourceDataEntries) {
Schema schema = sourceDataEntry.getSchema();
Object[] payload = sourceDataEntry.getPayload();
DataEntryBuilder dataEntryBuilder = new DataEntryBuilder(schema).entryType(sourceDataEntry.getEntryType()).queue(sourceDataEntry.getQueueName()).timestamp(sourceDataEntry.getTimestamp());
if (schema.getFields() != null) {
schema.getFields().forEach(field -> dataEntryBuilder.putFiled(field.getName(), payload[field.getIndex()]));
}
SinkDataEntry sinkDataEntry = dataEntryBuilder.buildSinkDataEntry(-1L);
sinkDataEntries.add(sinkDataEntry);
position = sourceDataEntry.getSourcePosition();
partition = sourceDataEntry.getSourcePartition();
}
try {
sinkTask.put(sinkDataEntries);
try {
if (null != position && null != partition) {
positionManagementService.putPosition(position, partition);
}
} catch (Exception e) {
log.error("Source task save position info failed.", e);
}
} catch (Exception e) {
log.error("Send message error, error info: {}.", e);
}
}
use of io.openmessaging.connector.api.data.SinkDataEntry in project rocketmq-externals by apache.
the class FileSinkTask method put.
@Override
public void put(Collection<SinkDataEntry> sinkDataEntries) {
for (SinkDataEntry record : sinkDataEntries) {
Object[] payloads = record.getPayload();
log.trace("Writing line to {}: {}", logFilename(), payloads);
Schema schema = record.getSchema();
List<Field> fields = schema.getFields();
for (Field field : fields) {
FieldType type = field.getType();
if (type.equals(FieldType.STRING)) {
log.info("Writing line to {}: {}", logFilename(), payloads[field.getIndex()]);
outputStream.println(String.valueOf(payloads[field.getIndex()]));
}
}
}
}
Aggregations