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;
}
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);
}
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);
}
}
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;
}
Aggregations