Search in sources :

Example 16 with Schema

use of io.openmessaging.connector.api.data.Schema 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);
    }
}
Also used : SinkDataEntry(io.openmessaging.connector.api.data.SinkDataEntry) SourceDataEntry(io.openmessaging.connector.api.data.SourceDataEntry) Schema(io.openmessaging.connector.api.data.Schema) ArrayList(java.util.ArrayList) DataEntryBuilder(io.openmessaging.connector.api.data.DataEntryBuilder) ByteBuffer(java.nio.ByteBuffer)

Example 17 with Schema

use of io.openmessaging.connector.api.data.Schema 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()]));
            }
        }
    }
}
Also used : Field(io.openmessaging.connector.api.data.Field) SinkDataEntry(io.openmessaging.connector.api.data.SinkDataEntry) Schema(io.openmessaging.connector.api.data.Schema) FieldType(io.openmessaging.connector.api.data.FieldType)

Example 18 with Schema

use of io.openmessaging.connector.api.data.Schema in project rocketmq-externals by apache.

the class TestSourceTask method poll.

@Override
public Collection<SourceDataEntry> poll() {
    Set<SourceDataEntry> sourceTasks = new HashSet<>();
    Object[] newPayload = new Object[1];
    newPayload[0] = Base64.getEncoder().encodeToString("test".getBytes());
    sourceTasks.add(new SourceDataEntry(ByteBuffer.wrap("1".getBytes()), ByteBuffer.wrap("2".getBytes()), System.currentTimeMillis(), EntryType.CREATE, "test-queue", new Schema(), newPayload));
    return sourceTasks;
}
Also used : SourceDataEntry(io.openmessaging.connector.api.data.SourceDataEntry) Schema(io.openmessaging.connector.api.data.Schema) HashSet(java.util.HashSet)

Aggregations

Schema (io.openmessaging.connector.api.data.Schema)18 SourceDataEntry (io.openmessaging.connector.api.data.SourceDataEntry)12 Field (io.openmessaging.connector.api.data.Field)9 JSONObject (com.alibaba.fastjson.JSONObject)8 DataEntryBuilder (io.openmessaging.connector.api.data.DataEntryBuilder)8 ArrayList (java.util.ArrayList)7 EntryType (io.openmessaging.connector.api.data.EntryType)6 SinkDataEntry (io.openmessaging.connector.api.data.SinkDataEntry)5 ByteBuffer (java.nio.ByteBuffer)5 HashMap (java.util.HashMap)3 Field (java.lang.reflect.Field)2 List (java.util.List)2 Position (org.apache.connect.mongo.replicator.Position)2 ReplicaSetConfig (org.apache.connect.mongo.replicator.ReplicaSetConfig)2 ReplicaSetsContext (org.apache.connect.mongo.replicator.ReplicaSetsContext)2 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2 RocketMQConverter (org.apache.rocketmq.connect.runtime.converter.RocketMQConverter)2 Document (org.bson.Document)2 Test (org.junit.Test)2 ConnectionString (com.mongodb.ConnectionString)1