Skip to content
/ pubsub Public

an implementation of the publish-subscribe messaging pattern in rust

Notifications You must be signed in to change notification settings

1nwf/pubsub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pubsub

an implementation of the publish-subscribe messaging pattern in rust

Usage

First of all, clone the repo:
git clone https://github.com/nwf03/pubsub.git

Server

cd pubsub/server and then run cargo run
This will start a TCP server listenting on 127.0.0.1:6379

Client

Example

use client::Client;
use std::thread;

fn main() {
    let mut subscriber = Client::new("localhost:6379");
    let channel_name = String::from("channel");
    thread::spawn(|| loop {
        let mut publisher = Client::new("localhost:6379");
        thread::sleep(Duration::from_millis(500));
        let channel_name = String::from("channel");
        let data = &String::from("hello!");
        publisher.publish(&channel_name, data)
    });

    subscriber.subscribe(&channel_name);
    for msg in subscriber.recieve_message() {
        println!("{}", msg);
    }

}

About

an implementation of the publish-subscribe messaging pattern in rust

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages