GithubHelp home page GithubHelp logo

mrpc's Introduction

mprc -- Arbitrary MongoDB Wire Protocol RPC Framework

Overview

MRPC is a set of tools to support writing RPC-like services using the MongoDB wire protocol as a transport layer. The idea is, if you have a MongoDB driver (or are a MongoDB driver,) you should be able to communicate with other services without needing a second client driver, or to fall back to shell scripting for interacting with tools and utility.

Furthermore, it should be trivially easy to use this kind of interface to wrap up functionality for arbitrary tools.

History

The "mongowire" and "bson" packages are heavily adapted from github.com/erh/mongonet. Indeed this repository retains that history.

Use

Create a new service instance with the NewService function:

service := NewService("127.0.0.1", 3000)

For each operation, you must define an mongowire.OpScope and a handler function, as in:

op := &mogowire.OpScope{
     Type:      mongowire.OP_COMMAND,
     Context:   "admin",
     Command:   "listCommand",
}

handler := func(ctx context.Context, w io.Writer, m mongowire.Message) {
     // operation implementation
}

Then register the operation:

err := service.RegisterOperation(op, handler)

The RegisterOperation method returns an error if the operation scope is not unique, or the handler is nil. You can validate an operation scope using its Validate method.

When you have defined all methods, you can start the service using the Run method:

err := service.Run(ctx)

The Run method returns an error if there are any issues starting the service or if the context is canceled.

Quirks

  • "Legacy" commands, which are issued as queries against a special collection are "up" converted to OP_COMMAND messages internally (though, mrpc does track that it has performed the conversion so you can see that.) Thus, you must register an OP_COMMAND, even if your clients are sending OP_QUERY messages.
  • Handler functions are responsible for determining the "appropriate" response, and the framework cannot ensure that OP_COMMAND requests get OP_COMMAND_REPLY messages.

Dependencies

Currently, mrpc does not vendor its dependencies, and uses:

mrpc's People

Contributors

dependabot[bot] avatar erh avatar john-morales avatar julianedwards avatar kimchelly avatar louisaberger avatar lydiastepanek avatar tychoish avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.