use of org.apache.pulsar.common.api.proto.KeyValue in project pulsar by yahoo.
the class MessageImpl method getKeyValueBySchemaVersion.
private T getKeyValueBySchemaVersion() {
KeyValueSchemaImpl kvSchema = getKeyValueSchema();
byte[] schemaVersion = getSchemaVersion();
if (kvSchema.getKeyValueEncodingType() == KeyValueEncodingType.SEPARATED) {
org.apache.pulsar.common.schema.KeyValue keyValue = (org.apache.pulsar.common.schema.KeyValue) kvSchema.decode(getKeyBytes(), getData(), schemaVersion);
if (schema instanceof AutoConsumeSchema) {
return (T) AutoConsumeSchema.wrapPrimitiveObject(keyValue, ((AutoConsumeSchema) schema).getSchemaInfo(schemaVersion).getType(), schemaVersion);
} else {
return (T) keyValue;
}
} else {
return decode(schemaVersion);
}
}
use of org.apache.pulsar.common.api.proto.KeyValue in project pulsar by yahoo.
the class TopicsImpl method getIndividualMsgsFromBatch.
private List<Message<byte[]>> getIndividualMsgsFromBatch(String topic, String msgId, byte[] data, Map<String, String> properties, MessageMetadata msgMetadataBuilder, BrokerEntryMetadata brokerEntryMetadata) {
List<Message<byte[]>> ret = new ArrayList<>();
int batchSize = Integer.parseInt(properties.get(BATCH_HEADER));
ByteBuf buf = Unpooled.wrappedBuffer(data);
for (int i = 0; i < batchSize; i++) {
String batchMsgId = msgId + ":" + i;
SingleMessageMetadata singleMessageMetadata = new SingleMessageMetadata();
try {
ByteBuf singleMessagePayload = Commands.deSerializeSingleMessageInBatch(buf, singleMessageMetadata, i, batchSize);
if (singleMessageMetadata.getPropertiesCount() > 0) {
for (KeyValue entry : singleMessageMetadata.getPropertiesList()) {
properties.put(entry.getKey(), entry.getValue());
}
}
MessageImpl message = new MessageImpl<>(topic, batchMsgId, properties, singleMessagePayload, Schema.BYTES, msgMetadataBuilder);
if (brokerEntryMetadata != null) {
message.setBrokerEntryMetadata(brokerEntryMetadata);
}
ret.add(message);
} catch (Exception ex) {
log.error("Exception occurred while trying to get BatchMsgId: {}", batchMsgId, ex);
}
}
buf.release();
return ret;
}
use of org.apache.pulsar.common.api.proto.KeyValue in project pulsar by yahoo.
the class EntryFilter2Test method filterEntry.
@Override
public FilterResult filterEntry(Entry entry, FilterContext context) {
if (context.getMsgMetadata() == null || context.getMsgMetadata().getPropertiesCount() <= 0) {
return FilterResult.ACCEPT;
}
List<KeyValue> list = context.getMsgMetadata().getPropertiesList();
// filter by subscription properties
PersistentSubscription subscription = (PersistentSubscription) context.getSubscription();
if (!MapUtils.isEmpty(subscription.getSubscriptionProperties())) {
for (KeyValue keyValue : list) {
if (subscription.getSubscriptionProperties().containsKey(keyValue.getKey())) {
return FilterResult.ACCEPT;
}
}
}
return FilterResult.REJECT;
}
use of org.apache.pulsar.common.api.proto.KeyValue in project pulsar by yahoo.
the class EntryFilterTest method filterEntry.
@Override
public FilterResult filterEntry(Entry entry, FilterContext context) {
if (context.getMsgMetadata() == null || context.getMsgMetadata().getPropertiesCount() <= 0) {
return FilterResult.ACCEPT;
}
Consumer consumer = context.getConsumer();
Map<String, String> metadata = consumer.getMetadata();
log.info("filterEntry for {}", metadata);
String matchValueAccept = metadata.getOrDefault("matchValueAccept", "ACCEPT");
String matchValueReject = metadata.getOrDefault("matchValueReject", "REJECT");
String matchValueReschedule = metadata.getOrDefault("matchValueReschedule", "RESCHEDULE");
List<KeyValue> list = context.getMsgMetadata().getPropertiesList();
// filter by string
for (KeyValue keyValue : list) {
if (matchValueAccept.equalsIgnoreCase(keyValue.getKey())) {
log.info("metadata {} key {} outcome ACCEPT", metadata, keyValue.getKey());
return FilterResult.ACCEPT;
} else if (matchValueReject.equalsIgnoreCase(keyValue.getKey())) {
log.info("metadata {} key {} outcome REJECT", metadata, keyValue.getKey());
return FilterResult.REJECT;
} else if (matchValueReschedule.equalsIgnoreCase(keyValue.getKey())) {
log.info("metadata {} key {} outcome RESCHEDULE", metadata, keyValue.getKey());
return FilterResult.RESCHEDULE;
} else {
log.info("metadata {} key {} outcome ??", metadata, keyValue.getKey());
}
}
return null;
}
use of org.apache.pulsar.common.api.proto.KeyValue in project incubator-pulsar by apache.
the class SchemaInfoUtil method newSchemaInfo.
public static SchemaInfo newSchemaInfo(Schema schema) {
SchemaInfoImpl.SchemaInfoImplBuilder si = SchemaInfoImpl.builder().name(schema.getName()).schema(schema.getSchemaData()).type(Commands.getSchemaType(schema.getType()));
if (schema.getPropertiesCount() == 0) {
si.properties(Collections.emptyMap());
} else {
Map<String, String> properties = new TreeMap<>();
for (int i = 0; i < schema.getPropertiesCount(); i++) {
KeyValue kv = schema.getPropertyAt(i);
properties.put(kv.getKey(), kv.getValue());
}
si.properties(properties);
}
return si.build();
}
Aggregations