Struct simple_pub_sub::client::Client
source · pub struct Client {
pub client_type: PubSubClient,
/* private fields */
}Expand description
Simple pub sub Client
Fields§
§client_type: PubSubClientImplementations§
source§impl Client
impl Client
sourcepub fn new(client_type: PubSubClient) -> Client
pub fn new(client_type: PubSubClient) -> Client
Creates a new instance of Client
Examples found in repository?
examples/subscribe_unix.rs (lines 11-13)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubUnixClient {
path: "/tmp/simple.sock".to_string(),
};
// initialize the client.
let mut client = simple_pub_sub::client::Client::new(
simple_pub_sub::client::PubSubClient::Unix(client_type),
);
// set the callback function.
client.on_message(on_msg);
// connect the client.
let _ = client.connect().await;
// subscribe to the given topic.
let _ = client.subscribe("abc".to_string()).await;
Ok(())
}More examples
examples/publish_unix.rs (lines 7-9)
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubUnixClient {
path: "/tmp/simple.sock".to_string(),
};
// initialize the client.
let mut client = simple_pub_sub::client::Client::new(
simple_pub_sub::client::PubSubClient::Unix(client_type),
);
// connect the client.
let _ = client.connect().await;
// subscribe to the given topic.
let _ = client
.publish(
"abc".to_string(),
"test message".to_string().into_bytes().to_vec(),
)
.await;
Ok(())
}examples/subscribe_tcp.rs (line 23)
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
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
cert: None,
cert_password: None,
};
let tls_client = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
cert: Some("cert.pem".to_string()),
cert_password: Some("password".to_string()),
};
// initialize the client.
let mut client =
simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
// set the callback function.
client.on_message(on_msg);
// connect the client.
let _ = client.connect().await;
// subscribe to the given topic.
let _ = client.subscribe("abc".to_string()).await;
Ok(())
}examples/publish_tcp.rs (line 19)
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
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
cert: None,
cert_password: None,
};
let tls_client = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
cert: Some("cert.pem".to_string()),
cert_password: Some("password".to_string()),
};
// initialize the client.
let mut client =
simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
// connect the client.
let _ = client.connect().await;
// subscribe to the given topic.
let _ = client
.publish(
"abc".to_string(),
"test message".to_string().into_bytes().to_vec(),
)
.await;
Ok(())
}sourcepub fn on_message(&mut self, callback: fn(_: String, _: Vec<u8>))
pub fn on_message(&mut self, callback: fn(_: String, _: Vec<u8>))
Sets the on_message callback function
Examples found in repository?
examples/subscribe_unix.rs (line 15)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubUnixClient {
path: "/tmp/simple.sock".to_string(),
};
// initialize the client.
let mut client = simple_pub_sub::client::Client::new(
simple_pub_sub::client::PubSubClient::Unix(client_type),
);
// set the callback function.
client.on_message(on_msg);
// connect the client.
let _ = client.connect().await;
// subscribe to the given topic.
let _ = client.subscribe("abc".to_string()).await;
Ok(())
}More examples
examples/subscribe_tcp.rs (line 25)
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
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
cert: None,
cert_password: None,
};
let tls_client = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
cert: Some("cert.pem".to_string()),
cert_password: Some("password".to_string()),
};
// initialize the client.
let mut client =
simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
// set the callback function.
client.on_message(on_msg);
// connect the client.
let _ = client.connect().await;
// subscribe to the given topic.
let _ = client.subscribe("abc".to_string()).await;
Ok(())
}sourcepub async fn connect(&mut self) -> Result<(), Error>
pub async fn connect(&mut self) -> Result<(), Error>
Connects to the server
Examples found in repository?
examples/subscribe_unix.rs (line 17)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubUnixClient {
path: "/tmp/simple.sock".to_string(),
};
// initialize the client.
let mut client = simple_pub_sub::client::Client::new(
simple_pub_sub::client::PubSubClient::Unix(client_type),
);
// set the callback function.
client.on_message(on_msg);
// connect the client.
let _ = client.connect().await;
// subscribe to the given topic.
let _ = client.subscribe("abc".to_string()).await;
Ok(())
}More examples
examples/publish_unix.rs (line 11)
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubUnixClient {
path: "/tmp/simple.sock".to_string(),
};
// initialize the client.
let mut client = simple_pub_sub::client::Client::new(
simple_pub_sub::client::PubSubClient::Unix(client_type),
);
// connect the client.
let _ = client.connect().await;
// subscribe to the given topic.
let _ = client
.publish(
"abc".to_string(),
"test message".to_string().into_bytes().to_vec(),
)
.await;
Ok(())
}examples/subscribe_tcp.rs (line 27)
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
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
cert: None,
cert_password: None,
};
let tls_client = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
cert: Some("cert.pem".to_string()),
cert_password: Some("password".to_string()),
};
// initialize the client.
let mut client =
simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
// set the callback function.
client.on_message(on_msg);
// connect the client.
let _ = client.connect().await;
// subscribe to the given topic.
let _ = client.subscribe("abc".to_string()).await;
Ok(())
}examples/publish_tcp.rs (line 21)
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
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
cert: None,
cert_password: None,
};
let tls_client = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
cert: Some("cert.pem".to_string()),
cert_password: Some("password".to_string()),
};
// initialize the client.
let mut client =
simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
// connect the client.
let _ = client.connect().await;
// subscribe to the given topic.
let _ = client
.publish(
"abc".to_string(),
"test message".to_string().into_bytes().to_vec(),
)
.await;
Ok(())
}sourcepub async fn post(&mut self, msg: Msg) -> Result<Vec<u8>, Error>
pub async fn post(&mut self, msg: Msg) -> Result<Vec<u8>, Error>
Sends the message to the given server and returns the ack the server could be either a tcp or unix server
sourcepub async fn publish(
&mut self,
topic: String,
message: Vec<u8>
) -> Result<(), Error>
pub async fn publish( &mut self, topic: String, message: Vec<u8> ) -> Result<(), Error>
Publishes the message to the given topic
Examples found in repository?
examples/publish_unix.rs (lines 14-17)
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubUnixClient {
path: "/tmp/simple.sock".to_string(),
};
// initialize the client.
let mut client = simple_pub_sub::client::Client::new(
simple_pub_sub::client::PubSubClient::Unix(client_type),
);
// connect the client.
let _ = client.connect().await;
// subscribe to the given topic.
let _ = client
.publish(
"abc".to_string(),
"test message".to_string().into_bytes().to_vec(),
)
.await;
Ok(())
}More examples
examples/publish_tcp.rs (lines 24-27)
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
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
cert: None,
cert_password: None,
};
let tls_client = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
cert: Some("cert.pem".to_string()),
cert_password: Some("password".to_string()),
};
// initialize the client.
let mut client =
simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
// connect the client.
let _ = client.connect().await;
// subscribe to the given topic.
let _ = client
.publish(
"abc".to_string(),
"test message".to_string().into_bytes().to_vec(),
)
.await;
Ok(())
}sourcepub async fn query(&mut self, topic: String) -> Result<String, Error>
pub async fn query(&mut self, topic: String) -> Result<String, Error>
Sends the query message to the server
sourcepub async fn subscribe(&mut self, topic: String) -> Result<(), Error>
pub async fn subscribe(&mut self, topic: String) -> Result<(), Error>
subscribes to the given topic
Examples found in repository?
examples/subscribe_unix.rs (line 19)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubUnixClient {
path: "/tmp/simple.sock".to_string(),
};
// initialize the client.
let mut client = simple_pub_sub::client::Client::new(
simple_pub_sub::client::PubSubClient::Unix(client_type),
);
// set the callback function.
client.on_message(on_msg);
// connect the client.
let _ = client.connect().await;
// subscribe to the given topic.
let _ = client.subscribe("abc".to_string()).await;
Ok(())
}More examples
examples/subscribe_tcp.rs (line 29)
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
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
cert: None,
cert_password: None,
};
let tls_client = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
cert: Some("cert.pem".to_string()),
cert_password: Some("password".to_string()),
};
// initialize the client.
let mut client =
simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
// set the callback function.
client.on_message(on_msg);
// connect the client.
let _ = client.connect().await;
// subscribe to the given topic.
let _ = client.subscribe("abc".to_string()).await;
Ok(())
}pub async fn write(&mut self, message: Vec<u8>) -> Result<(), Error>
pub async fn read(&mut self, message: &mut [u8]) -> Result<(), Error>
pub async fn read_buf(&mut self, message: &mut Vec<u8>) -> Result<(), Error>
pub async fn read_message(&mut self) -> Result<Msg, Error>
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Client
impl RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnwindSafe for Client
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more