@@ -150,6 +150,24 @@ private static void DeliveryReportCallbackImpl(IntPtr rk, IntPtr rkmessage, IntP
150
150
{
151
151
var msg = Util . Marshal . PtrToStructureUnsafe < rd_kafka_message > ( rkmessage ) ;
152
152
153
+ Headers headers = new Headers ( ) ;
154
+ LibRdKafka . message_headers ( rkmessage , out IntPtr hdrsPtr ) ;
155
+ if ( hdrsPtr != IntPtr . Zero )
156
+ {
157
+ for ( var i = 0 ; ; ++ i )
158
+ {
159
+ var err = LibRdKafka . header_get_all ( hdrsPtr , ( IntPtr ) i , out IntPtr namep , out IntPtr valuep , out IntPtr sizep ) ;
160
+ if ( err != ErrorCode . NoError )
161
+ {
162
+ break ;
163
+ }
164
+ var headerName = Util . Marshal . PtrToStringUTF8 ( namep ) ;
165
+ var headerValue = new byte [ ( int ) sizep ] ;
166
+ Marshal . Copy ( valuep , headerValue , 0 , ( int ) sizep ) ;
167
+ headers . Add ( new KeyValuePair < string , byte [ ] > ( headerName , headerValue ) ) ;
168
+ }
169
+ }
170
+
153
171
// the msg._private property has dual purpose. Here, it is an opaque pointer set
154
172
// by Topic.Produce to be an IDeliveryHandler. When Consuming, it's for internal
155
173
// use (hence the name).
@@ -193,7 +211,7 @@ private static void DeliveryReportCallbackImpl(IntPtr rk, IntPtr rkmessage, IntP
193
211
key ,
194
212
val ,
195
213
new Timestamp ( timestamp , ( TimestampType ) timestampType ) ,
196
- null ,
214
+ headers ,
197
215
msg . err
198
216
)
199
217
) ;
@@ -321,22 +339,22 @@ public Producer(IEnumerable<KeyValuePair<string, object>> config, bool manualPol
321
339
prop . Key != EnableBackgroundPollPropertyName &&
322
340
prop . Key != EnableDeliveryReportsPropertyName ) ;
323
341
324
- var enableBackgroundPollStr = ( string ) config . FirstOrDefault ( prop => prop . Key == EnableBackgroundPollPropertyName ) . Value ;
325
- if ( enableBackgroundPollStr != null )
342
+ var enableBackgroundPollObj = config . FirstOrDefault ( prop => prop . Key == EnableBackgroundPollPropertyName ) . Value ;
343
+ if ( enableBackgroundPollObj != null )
326
344
{
327
- this . manualPoll = ! bool . Parse ( enableBackgroundPollStr ) ;
345
+ this . manualPoll = ! bool . Parse ( enableBackgroundPollObj . ToString ( ) ) ;
328
346
}
329
347
330
- var enableDeliveryReportsStr = ( string ) config . FirstOrDefault ( prop => prop . Key == EnableDeliveryReportsPropertyName ) . Value ;
331
- if ( enableDeliveryReportsStr != null )
348
+ var enableDeliveryReportsObj = config . FirstOrDefault ( prop => prop . Key == EnableDeliveryReportsPropertyName ) . Value ;
349
+ if ( enableDeliveryReportsObj != null )
332
350
{
333
- this . disableDeliveryReports = ! bool . Parse ( enableDeliveryReportsStr ) ;
351
+ this . disableDeliveryReports = ! bool . Parse ( enableDeliveryReportsObj . ToString ( ) ) ;
334
352
}
335
353
336
- var blockIfQueueFullStr = ( string ) config . FirstOrDefault ( prop => prop . Key == BlockIfQueueFullPropertyName ) . Value ;
337
- if ( blockIfQueueFullStr != null )
354
+ var blockIfQueueFullObj = config . FirstOrDefault ( prop => prop . Key == BlockIfQueueFullPropertyName ) . Value ;
355
+ if ( blockIfQueueFullObj != null )
338
356
{
339
- this . blockIfQueueFullPropertyValue = bool . Parse ( blockIfQueueFullStr ) ;
357
+ this . blockIfQueueFullPropertyValue = bool . Parse ( blockIfQueueFullObj . ToString ( ) ) ;
340
358
}
341
359
342
360
// Note: Setting default topic configuration properties via default.topic.config is depreciated
@@ -404,8 +422,9 @@ public Producer(IEnumerable<KeyValuePair<string, object>> config, bool manualPol
404
422
/// librdkafka configuration parameters (refer to https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md).
405
423
/// </param>
406
424
public Producer ( IEnumerable < KeyValuePair < string , object > > config )
425
+ #pragma warning disable CS0618
407
426
: this ( config , false , false ) { }
408
-
427
+ #pragma warning restore CS0618
409
428
410
429
/// <include file='include_docs_producer.xml' path='API/Member[@name="Poll_int"]/*' />
411
430
public int Poll ( int millisecondsTimeout )
@@ -454,7 +473,7 @@ public Task<Message> ProduceAsync(Message message)
454
473
/// <include file='include_docs_producer.xml' path='API/Member[@name="ProduceAsync_string_TKey_TValue"]/*' />
455
474
/// <include file='include_docs_producer.xml' path='API/Member[@name="ProduceAsync_Common"]/*' />
456
475
public Task < Message > ProduceAsync ( string topic , byte [ ] key , byte [ ] val )
457
- => ProduceImpl ( topic , val , 0 , val ? . Length ?? 0 , key , 0 , key ? . Length ?? 0 , Timestamp . Default , Partition . NotSpecified , null , this . blockIfQueueFullPropertyValue ) ;
476
+ => ProduceImpl ( topic , val , 0 , val ? . Length ?? 0 , key , 0 , key ? . Length ?? 0 , Timestamp . Default , Partition . Any , null , this . blockIfQueueFullPropertyValue ) ;
458
477
459
478
/// <include file='include_docs_producer.xml' path='API/Member[@name="ProduceAsync_string_Partition_TKey_TValue_Timestamp_IEnumerable"]/*' />
460
479
/// <include file='include_docs_producer.xml' path='API/Member[@name="ProduceAsync_Common"]/*' />
@@ -492,7 +511,7 @@ public void Produce(Message message, IDeliveryHandler deliveryHandler)
492
511
/// <include file='include_docs_producer.xml' path='API/Member[@name="ProduceAsync_string_TKey_TValue"]/*' />
493
512
/// <include file='include_docs_producer.xml' path='API/Member[@name="Produce_IDeliveryHandler"]/*' />
494
513
public void Produce ( string topic , byte [ ] key , byte [ ] val , IDeliveryHandler deliveryHandler )
495
- => ProduceImpl ( topic , val , 0 , val ? . Length ?? 0 , key , 0 , key ? . Length ?? 0 , Timestamp . Default , Partition . NotSpecified , null , this . blockIfQueueFullPropertyValue , deliveryHandler ) ;
514
+ => ProduceImpl ( topic , val , 0 , val ? . Length ?? 0 , key , 0 , key ? . Length ?? 0 , Timestamp . Default , Partition . Any , null , this . blockIfQueueFullPropertyValue , deliveryHandler ) ;
496
515
497
516
/// <include file='include_docs_producer.xml' path='API/Member[@name="ProduceAsync_string_Partition_TKey_TValue_Timestamp_IEnumerable"]/*' />
498
517
/// <include file='include_docs_producer.xml' path='API/Member[@name="Produce_IDeliveryHandler"]/*' />
@@ -520,7 +539,7 @@ IDeliveryHandler deliveryHandler
520
539
/// <include file='include_docs_producer.xml' path='API/Member[@name="ProduceAsync_Obsolete"]/*' />
521
540
[ Obsolete ( "The Producer API has been revised and this overload of ProduceAsync has been depreciated. Please use another variant of ProduceAsync." ) ]
522
541
public Task < Message > ProduceAsync ( string topic , byte [ ] key , int keyOffset , int keyLength , byte [ ] val , int valOffset , int valLength )
523
- => ProduceImpl ( topic , val , valOffset , valLength , key , keyOffset , keyLength , Timestamp . Default , Partition . NotSpecified , null , this . blockIfQueueFullPropertyValue ) ;
542
+ => ProduceImpl ( topic , val , valOffset , valLength , key , keyOffset , keyLength , Timestamp . Default , Partition . Any , null , this . blockIfQueueFullPropertyValue ) ;
524
543
525
544
/// <include file='include_docs_producer.xml' path='API/Member[@name="ProduceAsync_Obsolete"]/*' />
526
545
[ Obsolete ( "The Producer API has been revised and this overload of ProduceAsync has been depreciated. Please use another variant of ProduceAsync." ) ]
@@ -535,17 +554,17 @@ public Task<Message> ProduceAsync(string topic, byte[] key, int keyOffset, int k
535
554
/// <include file='include_docs_producer.xml' path='API/Member[@name="ProduceAsync_Obsolete"]/*' />
536
555
[ Obsolete ( "Variants of ProduceAsync that include a blockIfQueueFull parameter are depreciated - use the dotnet.producer.block.if.queue.full configuration property instead." ) ]
537
556
public Task < Message > ProduceAsync ( string topic , byte [ ] key , int keyOffset , int keyLength , byte [ ] val , int valOffset , int valLength , bool blockIfQueueFull )
538
- => ProduceImpl ( topic , val , valOffset , valLength , key , keyOffset , keyLength , Timestamp . Default , Partition . NotSpecified , null , blockIfQueueFull ) ;
557
+ => ProduceImpl ( topic , val , valOffset , valLength , key , keyOffset , keyLength , Timestamp . Default , Partition . Any , null , blockIfQueueFull ) ;
539
558
540
559
/// <include file='include_docs_producer.xml' path='API/Member[@name="ProduceAsync_Obsolete"]/*' />
541
560
[ Obsolete ( "Variants of ProduceAsync that include a IDeliveryHandler parameter are depreciated - use a variant of Produce instead." ) ]
542
561
public void ProduceAsync ( string topic , byte [ ] key , byte [ ] val , IDeliveryHandler deliveryHandler )
543
- => ProduceImpl ( topic , val , 0 , val ? . Length ?? 0 , key , 0 , key ? . Length ?? 0 , Timestamp . Default , Partition . NotSpecified , null , this . blockIfQueueFullPropertyValue , deliveryHandler ) ;
562
+ => ProduceImpl ( topic , val , 0 , val ? . Length ?? 0 , key , 0 , key ? . Length ?? 0 , Timestamp . Default , Partition . Any , null , this . blockIfQueueFullPropertyValue , deliveryHandler ) ;
544
563
545
564
/// <include file='include_docs_producer.xml' path='API/Member[@name="ProduceAsync_Obsolete"]/*' />
546
565
[ Obsolete ( "Variants of ProduceAsync that include a IDeliveryHandler parameter are depreciated - use a variant of Produce instead." ) ]
547
566
public void ProduceAsync ( string topic , byte [ ] key , int keyOffset , int keyLength , byte [ ] val , int valOffset , int valLength , IDeliveryHandler deliveryHandler )
548
- => ProduceImpl ( topic , val , valOffset , valLength , key , keyOffset , keyLength , Timestamp . Default , Partition . NotSpecified , null , this . blockIfQueueFullPropertyValue , deliveryHandler ) ;
567
+ => ProduceImpl ( topic , val , valOffset , valLength , key , keyOffset , keyLength , Timestamp . Default , Partition . Any , null , this . blockIfQueueFullPropertyValue , deliveryHandler ) ;
549
568
550
569
/// <include file='include_docs_producer.xml' path='API/Member[@name="ProduceAsync_Obsolete"]/*' />
551
570
[ Obsolete ( "Variants of ProduceAsync that include a IDeliveryHandler parameter are depreciated - use a variant of Produce instead." ) ]
@@ -564,7 +583,7 @@ public void ProduceAsync(string topic, byte[] key, int keyOffset, int keyLength,
564
583
"Variants of ProduceAsync that include a IDeliveryHandler parameter are depreciated - use a variant of Produce instead. " +
565
584
"Variants of ProduceAsync that include a blockIfQueueFull parameter are depreciated - use the dotnet.producer.block.if.queue.full configuration property instead." ) ]
566
585
public void ProduceAsync ( string topic , byte [ ] key , int keyOffset , int keyLength , byte [ ] val , int valOffset , int valLength , bool blockIfQueueFull , IDeliveryHandler deliveryHandler )
567
- => ProduceImpl ( topic , val , valOffset , valLength , key , keyOffset , keyLength , Timestamp . Default , Partition . NotSpecified , null , blockIfQueueFull , deliveryHandler ) ;
586
+ => ProduceImpl ( topic , val , valOffset , valLength , key , keyOffset , keyLength , Timestamp . Default , Partition . Any , null , blockIfQueueFull , deliveryHandler ) ;
568
587
569
588
#endregion
570
589
0 commit comments