/
DependentProducerBuilder.cs
112 lines (98 loc) · 3.67 KB
/
DependentProducerBuilder.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2018 Confluent Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Refer to LICENSE for more information.
using System;
using System.Collections.Generic;
namespace Confluent.Kafka
{
/// <summary>
/// A builder class for <see cref="IProducer{TKey, TValue}" /> instance
/// implementations that leverage an existing client handle.
///
/// [API-SUBJECT-TO-CHANGE] - This class may be removed in the future
/// in favor of an improved API for this functionality.
/// </summary>
public class DependentProducerBuilder<TKey, TValue>
{
/// <summary>
/// The configured client handle.
/// </summary>
public Handle Handle { get; set; }
/// <summary>
/// The configured key serializer.
/// </summary>
public ISerializer<TKey> KeySerializer { get; set; }
/// <summary>
/// The configured value serializer.
/// </summary>
public ISerializer<TValue> ValueSerializer { get; set; }
/// <summary>
/// The configured async key serializer.
/// </summary>
public IAsyncSerializer<TKey> AsyncKeySerializer { get; set; }
/// <summary>
/// The configured async value serializer.
/// </summary>
public IAsyncSerializer<TValue> AsyncValueSerializer { get; set; }
/// <summary>
/// An underlying librdkafka client handle that the Producer will use to
/// make broker requests. The handle must be from another Producer
/// instance (not Consumer or AdminClient).
/// </summary>
public DependentProducerBuilder(Handle handle)
{
this.Handle = handle;
}
/// <summary>
/// The serializer to use to serialize keys.
/// </summary>
public DependentProducerBuilder<TKey, TValue> SetKeySerializer(ISerializer<TKey> serializer)
{
this.KeySerializer = serializer;
return this;
}
/// <summary>
/// The serializer to use to serialize values.
/// </summary>
public DependentProducerBuilder<TKey, TValue> SetValueSerializer(ISerializer<TValue> serializer)
{
this.ValueSerializer = serializer;
return this;
}
/// <summary>
/// The async serializer to use to serialize keys.
/// </summary>
public DependentProducerBuilder<TKey, TValue> SetKeySerializer(IAsyncSerializer<TKey> serializer)
{
this.AsyncKeySerializer = serializer;
return this;
}
/// <summary>
/// The async serializer to use to serialize values.
/// </summary>
public DependentProducerBuilder<TKey, TValue> SetValueSerializer(IAsyncSerializer<TValue> serializer)
{
this.AsyncValueSerializer = serializer;
return this;
}
/// <summary>
/// Build a new IProducer implementation instance.
/// </summary>
public virtual IProducer<TKey, TValue> Build()
{
return new Producer<TKey, TValue>(this);
}
}
}