@@ -8,7 +8,7 @@ use rdkafka::error::{KafkaError as NativeKafkaError, RDKafkaError};
8
8
use rdkafka:: message:: BorrowedMessage ;
9
9
use rdkafka:: util:: Timeout ;
10
10
use rdkafka:: { Message , TopicPartitionList } ;
11
- use std :: fmt :: Display ;
11
+ use serde :: { Deserialize , Serialize } ;
12
12
use std:: num:: ParseIntError ;
13
13
use std:: sync:: Arc ;
14
14
use std:: { collections:: HashMap , fmt:: Debug , str:: FromStr } ;
@@ -26,34 +26,13 @@ use crate::{
26
26
storage:: StreamType ,
27
27
} ;
28
28
29
- enum SslProtocol {
29
+ #[ derive( Debug , Deserialize , Serialize , Clone , Copy ) ]
30
+ pub enum SslProtocol {
30
31
Plaintext ,
31
32
Ssl ,
32
33
SaslPlaintext ,
33
34
SaslSsl ,
34
35
}
35
- impl Display for SslProtocol {
36
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
37
- f. write_str ( match self {
38
- SslProtocol :: Plaintext => "plaintext" ,
39
- SslProtocol :: Ssl => "ssl" ,
40
- SslProtocol :: SaslPlaintext => "sasl_plaintext" ,
41
- SslProtocol :: SaslSsl => "sasl_ssl" ,
42
- } )
43
- }
44
- }
45
- impl FromStr for SslProtocol {
46
- type Err = KafkaError ;
47
- fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
48
- match s. to_ascii_lowercase ( ) . as_str ( ) {
49
- "plaintext" => Ok ( SslProtocol :: Plaintext ) ,
50
- "ssl" => Ok ( SslProtocol :: Ssl ) ,
51
- "sasl_plaintext" => Ok ( SslProtocol :: SaslPlaintext ) ,
52
- "sasl_ssl" => Ok ( SslProtocol :: SaslSsl ) ,
53
- _ => Err ( KafkaError :: InvalidSslProtocolError ( s. to_string ( ) ) ) ,
54
- }
55
- }
56
- }
57
36
58
37
#[ allow( dead_code) ]
59
38
#[ derive( Debug , thiserror:: Error ) ]
@@ -150,9 +129,8 @@ fn setup_consumer() -> Result<(StreamConsumer, String), KafkaError> {
150
129
// conf.set("api.version.request", val.to_string());
151
130
// }
152
131
153
- if let Some ( val) = CONFIG . parseable . kafka_security_protocol . as_ref ( ) {
154
- let mapped: SslProtocol = val. parse ( ) ?;
155
- conf. set ( "security.protocol" , mapped. to_string ( ) ) ;
132
+ if let Some ( ssl_protocol) = CONFIG . parseable . kafka_security_protocol . as_ref ( ) {
133
+ conf. set ( "security.protocol" , serde_json:: to_string ( & ssl_protocol) ?) ;
156
134
}
157
135
158
136
let consumer: StreamConsumer = conf. create ( ) ?;
0 commit comments