本文整理了Java中org.apache.kafka.common.header.Header.value()
方法的一些代码示例,展示了Header.value()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Header.value()
方法的具体详情如下:
包路径:org.apache.kafka.common.header.Header
类名称:Header
方法名:value
暂无
代码示例来源: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
Iterator<Header> orignalTopicHeaderIterator = consumeRecord.headers().headers(ORGINAL_TOPIC).iterator();
if(orignalTopicHeaderIterator.hasNext()){
orignalTopic = serializer.deserialize(orignalTopicHeaderIterator.next().value());
} else{
orignalTopic = consumeRecord.topic();
while (iterator.hasNext()) {
Header next = iterator.next();
headerMap.put(next.key(), serializer.deserialize(next.value()));
代码示例来源:origin: QNJR-GROUP/EasyTransaction
Header next = iterator.next();
if (next.key().equals(RETRY_COUNT_KEY)) {
retryCount = serializer.deserialize(next.value());
continue;
代码示例来源:origin: apache/kafka
out.write(utf8Bytes);
byte[] headerValue = header.value();
if (headerValue == null) {
ByteUtils.writeVarint(-1, out);
代码示例来源:origin: apache/kafka
assertArrayEquals(record.headers().lastHeader("test").value(), "header2".getBytes());
代码示例来源:origin: apache/kafka
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("headerValue", new String(record.headers().lastHeader("headerKey").value(), StandardCharsets.UTF_8));
assertEquals("headerKey", record.headers().lastHeader("headerKey").key());
assertEquals("headerValue2", new String(record.headers().lastHeader("headerKey").value(), StandardCharsets.UTF_8));
assertEquals("headerKey", record.headers().lastHeader("headerKey").key());
代码示例来源:origin: spring-projects/spring-kafka
protected String retrieveHeaderAsString(Headers headers, String headerName) {
Iterator<Header> headerValues = headers.headers(headerName).iterator();
if (headerValues.hasNext()) {
Header headerValue = headerValues.next();
String classId = null;
if (headerValue.value() != null) {
classId = new String(headerValue.value(), StandardCharsets.UTF_8);
}
return classId;
}
return null;
}
代码示例来源: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
@Override
public void toHeaders(Headers source, Map<String, Object> target) {
source.forEach(header -> target.put(header.key(), header.value()));
}
代码示例来源:origin: spring-projects/spring-kafka
private Object decodeValue(Header h, Class<?> type)
throws IOException, JsonParseException, JsonMappingException, LinkageError {
final ObjectMapper headerObjectMapper = getObjectMapper();
Object value = headerObjectMapper.readValue(h.value(), type);
if (type.equals(NonTrustedHeaderType.class)) {
// Upstream NTHT propagated; may be trusted here...
NonTrustedHeaderType nth = (NonTrustedHeaderType) value;
if (trusted(nth.getUntrustedType())) {
try {
value = headerObjectMapper.readValue(nth.getHeaderValue(),
ClassUtils.forName(nth.getUntrustedType(), null));
}
catch (Exception e) {
logger.error("Could not decode header: " + nth, e);
}
}
}
return value;
}
代码示例来源:origin: spring-projects/spring-kafka
Header next = iterator.next();
if (next.key().equals(KafkaHeaders.CORRELATION_ID)) {
correlationId = new CorrelationKey(next.value());
代码示例来源:origin: spring-projects/spring-kafka
logger.error("Could not decode json type: " + new String(h.value()) + " for key: " + h
.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
@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
@Test
public void unitTests() throws Exception {
ErrorHandlingDeserializer2<String> ehd = new ErrorHandlingDeserializer2<>(new StringDeserializer());
assertThat(ehd.deserialize("topic", "foo".getBytes())).isEqualTo("foo");
ehd.close();
ehd = new ErrorHandlingDeserializer2<>(new Deserializer<String>() {
@Override
public void configure(Map<String, ?> configs, boolean isKey) {
}
@Override
public String deserialize(String topic, byte[] data) {
throw new RuntimeException("fail");
}
@Override
public void close() {
}
});
Headers headers = new RecordHeaders();
Object result = ehd.deserialize("topic", headers, "foo".getBytes());
assertThat(result).isNull();
Header deser = headers.lastHeader(ErrorHandlingDeserializer2.VALUE_DESERIALIZER_EXCEPTION_HEADER);
assertThat(new ObjectInputStream(new ByteArrayInputStream(deser.value())).readObject()).isInstanceOf(DeserializationException.class);
ehd.close();
}
代码示例来源:origin: spring-projects/spring-kafka
Header next = iterator.next();
assertThat(next.key()).isEqualTo("foo");
assertThat(new String(next.value())).isEqualTo("\"bar\"");
assertThat(iterator.hasNext()).isTrue();
next = iterator.next();
内容来源于网络,如有侵权,请联系作者删除!