Crates.io | nestjs-nats-connector |
lib.rs | nestjs-nats-connector |
version | 0.3.0 |
source | src |
created_at | 2022-02-14 05:42:19.44104 |
updated_at | 2022-02-14 11:38:25.332877 |
description | nestjs nats connector |
homepage | |
repository | https://github.com/mohammadjavad948/nestjs-nats-connector |
max_upload_size | |
id | 532021 |
size | 8,166 |
a simple crate that interacts with nestjs over nats
use std::error::Error;
use async_nats::{Connection, Message};
use nestjs_nats_connector::listener;
use nestjs_nats_connector::listener::IncomingRequest;
use serde::{Deserialize, Serialize};
use async_trait::async_trait;
#[derive(Serialize, Deserialize)]
pub struct Pattern {
cmd: String
}
pub struct Handler {
}
#[async_trait]
impl listener::Listener for Handler {
type Pattern = Pattern;
type RequestData = u32;
async fn handler(
&self,
connection: &Connection,
message: &Message,
data: IncomingRequest<Self::Pattern, Self::RequestData>
) {
println!("{}", data.id)
}
fn get_pattern(&self) -> Self::Pattern {
Pattern {
cmd: "dashboard.graph".to_string()
}
}
}
impl Handler {
pub fn new() -> Handler {
Handler { }
}
}
async fn test(){
let connection = async_nats::connect("localhost:4222")
.await
.expect("cant connect to nats server");
nestjs_nats_connector::listener::listen(
&connection,
vec![
Handler::new()
]
).await;
}