Class Headers
A collection of Kafka message headers.
Inherited Members
Namespace: Confluent.Kafka
Assembly: Confluent.Kafka.dll
Syntax
public class Headers : IEnumerable<IHeader>, IEnumerable
Remarks
Message headers are supported by v0.11 brokers and above.
Properties
BackingList
Gets the underlying list of headers
Declaration
public IReadOnlyList<IHeader> BackingList { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<IHeader> |
Count
The number of headers in the collection.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
this[int]
Gets the header at the specified index
Declaration
public IHeader this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
int | index |
Property Value
Type | Description |
---|---|
IHeader |
Methods
Add(Header)
Append a new header to the collection.
Declaration
public void Add(Header header)
Parameters
Type | Name | Description |
---|---|---|
Header | header | The header to add to the collection. |
Add(string, byte[])
Append a new header to the collection.
Declaration
public void Add(string key, byte[] val)
Parameters
Type | Name | Description |
---|---|---|
string | key | The header key. |
byte[] | val | The header value (possibly null). Note: A null header value is distinct from an empty header value (array of length 0). |
GetEnumerator()
Returns an enumerator that iterates through the headers collection.
Declaration
public IEnumerator<IHeader> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<IHeader> | An enumerator object that can be used to iterate through the headers collection. |
GetLastBytes(string)
Get the value of the latest header with the specified key.
Declaration
public byte[] GetLastBytes(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key to get the associated value of. |
Returns
Type | Description |
---|---|
byte[] | The value of the latest element in the collection with the specified key. |
Exceptions
Type | Condition |
---|---|
KeyNotFoundException | The key |
Remove(string)
Removes all headers for the given key.
Declaration
public void Remove(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key to remove all headers for |
TryGetLastBytes(string, out byte[])
Try to get the value of the latest header with the specified key.
Declaration
public bool TryGetLastBytes(string key, out byte[] lastHeader)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key to get the associated value of. |
byte[] | lastHeader | The value of the latest element in the collection with the specified key, if a header with that key was present in the collection. |
Returns
Type | Description |
---|---|
bool | true if the a value with the specified key was present in the collection, false otherwise. |