MCPcopy Index your code
hub / github.com/cetra3/tmq

github.com/cetra3/tmq @0.5.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.5.0 ↗ · + Follow
145 symbols 423 edges 35 files 50 documented · 34%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

TMQ - Rust ZeroMQ bindings for Tokio

This crate bridges Tokio and ZeroMQ to allow for ZeroMQ in the async world.

Crates.io Docs.rs MIT licensed

Changelog

0.5.0 - Extra setters/getters & new rust edition

  • Added setters for curve key encryption #45
  • Remove Redundant Imports #43
  • Add more socket options & bump edition #46

0.4.0 - Bump Deps

Bump Deps & Pin future in RequestSender #39

0.3.1 - Iter Mut for Multipart

Adds an iter_mut() method to Multipart

0.3.0 - Tokio 1.0 Support

0.3.0 adds support for tokio 1.0 thanks to YushiOMOTE!

Currently Implemented Sockets

  • Request/Reply
  • Publish/Subscribe
  • Dealer/Router
  • Push/Pull

Examples

Please see the examples directory for a full set of examples. They are paired together based upon the socket types.

Usage

Usage is made to be simple, but opinionated. See the examples for working code, but in general, you need to import tokio and tmq::*

Publish

To publish messages to all connected subscribers, you can use the publish function:

use tmq::{publish, Context, Result};

use futures::SinkExt;
use log::info;
use std::env;
use std::time::Duration;
use tokio::time::delay_for;

#[tokio::main]
async fn main() -> Result<()> {

    let mut socket = publish(&Context::new()).bind("tcp://127.0.0.1:7899")?;

    let mut i = 0;

    loop {
        i += 1;

        socket
            .send(vec!["topic", &format!("Broadcast #{}", i)])
            .await?;

        delay_for(Duration::from_secs(1)).await;
    }
}

Subscribe

a subscribe socket is a Stream that reads in values from a publish socket. You specify the filter prefix using the subscribe method, using "" for all messages.

use futures::StreamExt;

use tmq::{subscribe, Context, Result};

use std::env;

#[tokio::main]
async fn main() -> Result<()> {

    let mut socket = subscribe(&Context::new())
        .connect("tcp://127.0.0.1:7899")?
        .subscribe(b"topic")?;

    while let Some(msg) = socket.next().await {
        println!(
            "Subscribe: {:?}",
            msg?.iter()
                .map(|item| item.as_str().unwrap_or("invalid text"))
                .collect::<Vec<&str>>()
        );
    }
    Ok(())
}

Extension points exported contracts — how you extend this code

FromZmqSocket (Interface)
(no doc) [9 implementers]
src/socket_types/mod.rs
AsZmqSocket (Interface)
Trait for various ZMQ socket wrappers. [1 implementers]
src/socket.rs
SocketExt (Interface)
Trait which defines configuration functions for ZMQ sockets. See ZMQ documentation for more info: [http://api.zeromq.or [1 …
src/socket.rs

Core symbols most depended-on inside this repo

generate_tcp_address
called by 35
tests/utils.rs
bind
called by 33
src/socket_builder.rs
connect
called by 32
src/socket_builder.rs
send
called by 26
src/socket_types/request_reply.rs
into_iter
called by 19
src/message.rs
dealer
called by 14
src/socket_types/dealer.rs
pop_front
called by 11
src/poll.rs
get_socket
called by 10
src/poll.rs

Shape

Function 69
Method 53
Class 19
Interface 3
Enum 1

Languages

Rust100%

Modules by API surface

src/poll.rs17 symbols
src/message.rs15 symbols
tests/utils.rs13 symbols
tests/dealer.rs9 symbols
src/socket_types/router.rs7 symbols
src/socket_types/request_reply.rs7 symbols
tests/router.rs6 symbols
src/socket_types/subscribe.rs6 symbols
src/comm.rs6 symbols
tests/push.rs5 symbols
tests/pull.rs5 symbols
src/socket_builder.rs5 symbols

For agents

$ claude mcp add tmq \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page