Search in sources :

Example 21 with SourceDataEntry

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

the class RedisEntryConverter method kVEntryToDataEntries.

@Override
public List<SourceDataEntry> kVEntryToDataEntries(KVEntry kvEntry) {
    Schema schema = getRedisSchema(kvEntry.getValueType());
    String partition = kvEntry.getPartition();
    if (partition == null) {
        throw new IllegalStateException("partition info error.");
    }
    List<SourceDataEntry> res = new ArrayList<>();
    List<Object> values = splitValue(kvEntry.getValueType(), kvEntry.getValue(), this.maxValueSize);
    for (int i = 0; i < values.size(); i++) {
        DataEntryBuilder builder = newDataEntryBuilderWithoutValue(schema, kvEntry);
        builder.putFiled(Options.REDIS_VALUE.name(), values.get(i));
        builder.timestamp(System.currentTimeMillis());
        SourceDataEntry entry = builder.buildSourceDataEntry(ByteBuffer.wrap(kvEntry.getPartition().getBytes()), ByteBuffer.wrap(RedisPositionConverter.longToJson(kvEntry.getOffset()).toJSONString().getBytes()));
        res.add(entry);
    }
    return res;
}
Also used : 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)

Example 22 with SourceDataEntry

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

the class RabbitmqSourceTaskTest method test.

// @Test
public void test() throws InterruptedException {
    KeyValue kv = new DefaultKeyValue();
    kv.put("rabbitmqUrl", "amqp://112.74.48.251:5672");
    kv.put("rabbitmqUsername", "admin");
    kv.put("rabbitmqPassword", "admin");
    kv.put("destinationType", "queue");
    kv.put("destinationName", "test-queue");
    RabbitmqSourceTask task = new RabbitmqSourceTask();
    task.start(kv);
    for (int i = 0; i < 20; ) {
        Collection<SourceDataEntry> sourceDataEntry = task.poll();
        i = i + sourceDataEntry.size();
        System.out.println(sourceDataEntry);
    }
    Thread.sleep(20000);
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) SourceDataEntry(io.openmessaging.connector.api.data.SourceDataEntry)

Example 23 with SourceDataEntry

use of io.openmessaging.connector.api.data.SourceDataEntry 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 24 with SourceDataEntry

use of io.openmessaging.connector.api.data.SourceDataEntry 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

SourceDataEntry (io.openmessaging.connector.api.data.SourceDataEntry)24 Schema (io.openmessaging.connector.api.data.Schema)12 DataEntryBuilder (io.openmessaging.connector.api.data.DataEntryBuilder)8 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 JSONObject (com.alibaba.fastjson.JSONObject)6 Field (io.openmessaging.connector.api.data.Field)5 ByteBuffer (java.nio.ByteBuffer)5 EntryType (io.openmessaging.connector.api.data.EntryType)4 Field (java.lang.reflect.Field)4 HashMap (java.util.HashMap)4 KeyValue (io.openmessaging.KeyValue)3 BytesMessage (javax.jms.BytesMessage)3 MapMessage (javax.jms.MapMessage)3 Message (javax.jms.Message)3 ObjectMessage (javax.jms.ObjectMessage)3 StreamMessage (javax.jms.StreamMessage)3 TextMessage (javax.jms.TextMessage)3 MQClientException (org.apache.rocketmq.client.exception.MQClientException)3 KVEntry (org.apache.rocketmq.connect.redis.pojo.KVEntry)3