本文整理了Java中org.apache.kafka.common.header.Header.key()
方法的一些代码示例,展示了Header.key()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Header.key()
方法的具体详情如下:
包路径:org.apache.kafka.common.header.Header
类名称:Header
方法名:key
暂无
代码示例来源:origin: apache/kafka
protected Header makeNext() {
while (true) {
if (original.hasNext()) {
Header header = original.next();
if (!header.key().equals(key))
continue;
return header;
}
return this.allDone();
}
}
}
代码示例来源:origin: apache/kafka
@Override
public Header lastHeader(String key) {
checkKey(key);
for (int i = headers.size() - 1; i >= 0; i--) {
Header header = headers.get(i);
if (header.key().equals(key)) {
return header;
}
}
return null;
}
代码示例来源:origin: apache/kafka
@Override
public Headers remove(String key) throws IllegalStateException {
canWrite();
checkKey(key);
Iterator<Header> iterator = iterator();
while (iterator.hasNext()) {
if (iterator.next().key().equals(key)) {
iterator.remove();
}
}
return this;
}
代码示例来源:origin: openzipkin/brave
void clearHeaders(Headers headers) {
// Headers::remove creates and consumes an iterator each time. This does one loop instead.
for (Iterator<Header> i = headers.iterator(); i.hasNext(); ) {
Header next = i.next();
if (propagationKeys.contains(next.key())) i.remove();
}
}
代码示例来源:origin: apache/nifi
private Map<String, String> getAttributes(final ConsumerRecord<?, ?> consumerRecord) {
final Map<String, String> attributes = new HashMap<>();
if (headerNamePattern == null) {
return attributes;
}
for (final Header header : consumerRecord.headers()) {
final String attributeName = header.key();
if (headerNamePattern.matcher(attributeName).matches()) {
attributes.put(attributeName, new String(header.value(), headerCharacterSet));
}
}
return attributes;
}
代码示例来源:origin: apache/nifi
private Map<String, String> getAttributes(final ConsumerRecord<?, ?> consumerRecord) {
final Map<String, String> attributes = new HashMap<>();
if (headerNamePattern == null) {
return attributes;
}
for (final Header header : consumerRecord.headers()) {
final String attributeName = header.key();
if (headerNamePattern.matcher(attributeName).matches()) {
attributes.put(attributeName, new String(header.value(), headerCharacterSet));
}
}
return attributes;
}
代码示例来源:origin: apache/nifi
private Map<String, String> getAttributes(final ConsumerRecord<?, ?> consumerRecord) {
final Map<String, String> attributes = new HashMap<>();
if (headerNamePattern == null) {
return attributes;
}
for (final Header header : consumerRecord.headers()) {
final String attributeName = header.key();
if (headerNamePattern.matcher(attributeName).matches()) {
attributes.put(attributeName, new String(header.value(), headerCharacterSet));
}
}
return attributes;
}
代码示例来源:origin: apache/kafka
static void assertHeader(String key, String value, Header actual) {
assertEquals(key, actual.key());
assertTrue(Arrays.equals(value.getBytes(), actual.value()));
}
代码示例来源:origin: apache/kafka
private static int sizeOf(int keySize, int valueSize, Header[] headers) {
int size = 0;
if (keySize < 0)
size += NULL_VARINT_SIZE_BYTES;
else
size += ByteUtils.sizeOfVarint(keySize) + keySize;
if (valueSize < 0)
size += NULL_VARINT_SIZE_BYTES;
else
size += ByteUtils.sizeOfVarint(valueSize) + valueSize;
if (headers == null)
throw new IllegalArgumentException("Headers cannot be null");
size += ByteUtils.sizeOfVarint(headers.length);
for (Header header : headers) {
String headerKey = header.key();
if (headerKey == null)
throw new IllegalArgumentException("Invalid null header key found in headers");
int headerKeySize = Utils.utf8Length(headerKey);
size += ByteUtils.sizeOfVarint(headerKeySize) + headerKeySize;
byte[] headerValue = header.value();
if (headerValue == null) {
size += NULL_VARINT_SIZE_BYTES;
} else {
size += ByteUtils.sizeOfVarint(headerValue.length) + headerValue.length;
}
}
return size;
}
代码示例来源:origin: QNJR-GROUP/EasyTransaction
while (iterator.hasNext()) {
Header next = iterator.next();
if (next.key().equals(RETRY_COUNT_KEY)) {
retryCount = serializer.deserialize(next.value());
continue;
if(next.key().equals(ORGINAL_TOPIC)){
hasOrignalHeader = true;
代码示例来源:origin: QNJR-GROUP/EasyTransaction
while (iterator.hasNext()) {
Header next = iterator.next();
headerMap.put(next.key(), serializer.deserialize(next.value()));
代码示例来源:origin: apache/kafka
String headerKey = header.key();
if (headerKey == null)
throw new IllegalArgumentException("Invalid null header key found in headers");
代码示例来源:origin: apache/kafka
for (Record record : splitBatch) {
assertTrue("Header size should be 1.", record.headers().length == 1);
assertTrue("Header key should be 'header-key'.", record.headers()[0].key().equals("header-key"));
assertTrue("Header value should be 'header-value'.", new String(record.headers()[0].value()).equals("header-value"));
代码示例来源:origin: apache/kafka
assertEquals("headerKey", record.headers().lastHeader("headerKey").key());
assertEquals("headerKey", record.headers().lastHeader("headerKey").key());
代码示例来源:origin: spring-projects/spring-kafka
@Override
public void toHeaders(Headers source, Map<String, Object> target) {
source.forEach(header -> target.put(header.key(), header.value()));
}
代码示例来源:origin: spring-projects/spring-kafka
final Map<String, String> jsonTypes = decodeJsonTypes(source);
source.forEach(h -> {
if (!(h.key().equals(JSON_TYPES))) {
if (jsonTypes != null && jsonTypes.containsKey(h.key())) {
Class<?> type = Object.class;
String requestedType = jsonTypes.get(h.key());
boolean trusted = false;
try {
logger.error("Could not load class for header: " + h.key(), e);
headers.put(h.key(), value);
.key(),
e);
headers.put(h.key(), h.value());
headers.put(h.key(), new NonTrustedHeaderType(h.value(), requestedType));
headers.put(h.key(), h.value());
代码示例来源:origin: spring-projects/spring-kafka
@SuppressWarnings("unchecked")
@Nullable
private Map<String, String> decodeJsonTypes(Headers source) {
Map<String, String> types = null;
Iterator<Header> iterator = source.iterator();
ObjectMapper headerObjectMapper = getObjectMapper();
while (iterator.hasNext()) {
Header next = iterator.next();
if (next.key().equals(JSON_TYPES)) {
try {
types = headerObjectMapper.readValue(next.value(), Map.class);
}
catch (IOException e) {
logger.error("Could not decode json types: " + new String(next.value()), e);
}
break;
}
}
return types;
}
代码示例来源:origin: spring-projects/spring-kafka
while (correlationId == null && iterator.hasNext()) {
Header next = iterator.next();
if (next.key().equals(KafkaHeaders.CORRELATION_ID)) {
correlationId = new CorrelationKey(next.value());
代码示例来源:origin: spring-projects/spring-kafka
@Test
public void testNoMapper() {
BatchMessagingMessageConverter batchMessageConverter = new BatchMessagingMessageConverter();
batchMessageConverter.setHeaderMapper(null);
MessageHeaders headers = testGuts(batchMessageConverter);
@SuppressWarnings("unchecked")
List<Headers> natives = (List<Headers>) headers.get(KafkaHeaders.NATIVE_HEADERS);
assertThat(natives).hasSize(3);
Iterator<Header> iterator = natives.get(0).iterator();
assertThat(iterator.hasNext()).isEqualTo(true);
Header next = iterator.next();
assertThat(next.key()).isEqualTo("foo");
assertThat(new String(next.value())).isEqualTo("bar");
}
代码示例来源:origin: spring-projects/spring-kafka
Iterator<Header> iterator = headers.iterator();
while (iterator.hasNext() && !hasReplyTopic) {
if (iterator.next().key().equals(KafkaHeaders.REPLY_TOPIC)) {
hasReplyTopic = true;
内容来源于网络,如有侵权,请联系作者删除!