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
113
114
115
116
117
118
119
120
use serde_derive::{Serialize, Deserialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Config {
pub client_id: Option<String>,
pub hostname: Option<String>,
pub feature_negotiation: bool,
pub heartbeat_interval: i64,
pub output_buffer_size: u64,
pub output_buffer_timeout: u32,
pub tls_v1: bool,
pub snappy: bool,
pub deflate: bool,
pub deflate_level: u16,
pub sample_rate: u16,
pub user_agent: String,
pub message_timeout: u32,
}
use hostname::get_hostname;
impl Default for Config {
fn default() -> Config {
Config {
client_id: get_hostname(),
user_agent: String::from("nsqueue"),
hostname: get_hostname(),
deflate: false,
deflate_level: 6,
snappy: false,
feature_negotiation: true,
heartbeat_interval: 30000,
message_timeout: 0,
output_buffer_size: 16384,
output_buffer_timeout: 250,
sample_rate: 0,
tls_v1: false,
}
}
}
#[derive(Clone, Debug, Deserialize)]
pub struct NsqdConfig {
pub max_rdy_count: u32,
pub version: String,
pub max_msg_timeout: u64,
pub msg_timeout: u64,
pub tls_v1: bool,
pub deflate: bool,
pub deflate_level: u16,
pub max_deflate_level: u16,
pub snappy: bool,
pub sample_rate: u16,
pub auth_required: bool,
pub output_buffer_size: u64,
pub output_buffer_timeout: u32,
}
#[allow(dead_code)]
impl Config {
pub fn new() -> Config {
Config{ ..Default::default() }
}
pub fn client_id(mut self, client_id: String) -> Self {
self.client_id = Some(client_id);
self
}
pub fn hostname(mut self, hostname: String) -> Self {
self.hostname = Some(hostname);
self
}
pub fn user_agent(mut self, user_agent: String) -> Self {
self.user_agent = user_agent;
self
}
pub fn snappy(mut self, snappy: bool) -> Self {
self.snappy = snappy;
self
}
}