-
Notifications
You must be signed in to change notification settings - Fork 233
/
Copy pathJsonConsumer.cs
40 lines (35 loc) · 988 Bytes
/
JsonConsumer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.Linq;
using KafkaNet.Model;
using KafkaNet.Protocol;
using Newtonsoft.Json;
namespace KafkaNet.Client
{
public class JsonConsumer<T> : IDisposable
{
private readonly Consumer _consumer;
public JsonConsumer(IBrokerRouter brokerRouter, IKafkaLog log, ConsumerOptions options)
{
_consumer = new Consumer(brokerRouter, log, options);
}
public IEnumerable<Message<T>> Consume()
{
return _consumer.Consume()
.Select(response => new Message<T>
{
Meta = response.Meta,
Value = JsonConvert.DeserializeObject<T>(response.Value)
});
}
public void Dispose()
{
using (_consumer) { }
}
}
public class Message<T>
{
public MessageMetadata Meta { get; set; }
public T Value { get; set; }
}
}