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("nsq_client"),
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<S: Into<String>>(mut self, client_id: S) -> Self {
self.client_id = Some(client_id.into());
self
}
pub fn hostname<S: Into<String>>(mut self, hostname: S) -> Self {
self.hostname = Some(hostname.into());
self
}
pub fn user_agent<S: Into<String>>(mut self, user_agent: S) -> Self {
self.user_agent = user_agent.into();
self
}
}