npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@usherlabs/protobuf-zmq-ts-transport

v0.0.1

Published

A transport layer for to sit between protobuf and zmq

Downloads

2

Readme

protobuf-zmq-ts-transport

This is a package that allows you to use the protobuf-ts library and ZeroMQ messaging system together, aiding in efficient data transmission between processes via sockets. It supports both the pub-sub and request-reply patterns.

Originally designed to facilitate communication between a NodeJS client and a Rust server, this package can be adapted to any language that adheres to this protocol.

How to Use

Follow these steps to make use of this library:

  1. Refer to the protobuf-ts documentation to generate a client file for your .proto services.
  2. Establish and connect a SUB and DEALER ZeroMQ socket.
  3. Construct a ZMQClientTransport object and pass it as an argument when creating a service client.
  4. Make sure a service is operational and capable of either publishing data or responding to requests.
  5. Activate any method from the client to either subscribe to a certain topic or request data.

For more comprehensive examples, refer to our test files.

Implementation Details

In this section, we will discuss the design decisions that went into this package. It's not necessary to understand every detail to use this package, but it may be helpful to understand its limitations.

Solution Goals

  • Facilitate inter-process communication while minimizing required modifications when extending the API.
  • Ensure type safety.
  • Offer the ability to create a data stream across different subscribed processes.
  • Simplify the creation of asynchronous request-reply tasks between processes.

Given these, we have 2 patterns in operation:

1. Pub/Sub Pattern

  • A PUBLISHER application binds to a socket. Any number of SUBSCRIBER applications can connect.
  • For communication, the ZMQ frame protocol should be: [methodName, Output], in bytes
    message EmptyInput {}
    
    message SubscriptionItem {
      string data = 1;
    }
    
    service MyServerService {
      rpc SubscribeToItems(EmptyInput) returns (stream SubscriptionItem) {}
    }

The data transferred should be ["SubscribeToItems", SubscriptionItem].

  • Pub-sub methods should start with "SubscribeTo...". Later we will provide a idiomatic way to define this leveraging protobuf options.
  • Clients can subscribe and filter events using the methodName message.
  • The .proto file defined return type should be a data stream.

2. Request/Reply Pattern

  • ROUTER/DEALER sockets are used to allow asynchronous requests.
  • A server should handle multiple requests concurrently.
  • The ZMQ frame protocol should be: [requestId, BLANK, methodName, Input], in bytes. The server should reply with [clientId, requestId, Output]
    message MyRequestInput {
      int32 time_to_sleep = 1;
    }
    
    message MyRequestResult {
      bool all_ok = 1;
      string message = 2;
    }
    
    service MyServerService {
        rpc MyRequestMethod(MyRequestInput) returns (MyRequestResult) {}
    }
    The transferred data for this example should be [requestId, BLANK, "MyRequestMethod", MyRequestInput].
    • requestId is a randomly generated string by the client
    • BLANK is an empty frame, used to mimic the original protocol for REQUEST/REPLY patterns.
    • clientId is included by default by clients. ROUTER should also include this in the reply to ensure the correct dispatching of the reply to a client.

It's possible to use both patterns on the same service:

Note: Currently, we only support building Client implementations with this package. Future updates may include Server implementations.

Resources

  • protobuf-zmq-rust-generator: The Rust implementation that permits us to communicate using this protocol
  • ZeroMQ: The messaging library used to transmit data between processes
  • protobuf-ts: The protobuf library used to generate the client files

Contributing

We welcome contributions to this project!