Giter Club home page Giter Club logo

thrift-nats's Introduction

thrift-nats

Disclaimer: This repo is no longer maintained.

Support for using NATS as a Thrift RPC transport.

Server Usage

options := nats.DefaultOptions
conn, err := options.Connect()
if err != nil {
    panic(err)
}

var (
    transportFactory = thrift.NewTBufferedTransportFactory(8192)
    protocolFactory  = thrift.NewTJSONProtocolFactory()
    server           = thrift_nats.NewNATSServer(conn, "my-service", -1, 5*time.Second,
        processor, transportFactory, protocolFactory)
)

if err := server.Serve(); err != nil {
    panic(err)
}

Client Usage

options := nats.DefaultOptions
conn, err := options.Connect()
if err != nil {
    panic(err)
}

var (
    transportFactory = thrift.NewTBufferedTransportFactory(8192)
    protocolFactory  = thrift.NewTJSONProtocolFactory()
)

transport, err := thrift_nats.NATSTransportFactory(conn, "my-service", time.Second, time.Second)
if err != nil {
    panic(err)
}
transport = transportFactory.GetTransport(transport)

defer transport.Close()
if err := transport.Open(); err != nil {
    panic(err)
}

handleClient(tutorial.NewCalculatorClientFactory(transport, protocolFactory))

How It Works

A thrift-nats server has a specified NATS subject which it listens on. A client publishes a handshake message on this subject containing the inbox it expects responses to requests on. The handshake is delivered round-robin to a server which then responds and provides an inbox for the client to send requests on and, optionally, a heartbeat deadline. The server then begins accepting requests on the inbox, and the client can begin sending requests. If a heartbeat deadline is specified, the client periodically emits a heartbeat telling the server that it's still alive within the specified interval. If the client misses more than three heartbeats, the server closes the client's session and attempts to signal the client of the disconnect. When the client transport is closed, it attempts to signal the server so the session can be closed. The heartbeat acts as a fail-safe in the event that the disconnect signal is missed by the server.

thrift-nats's People

Contributors

tylertreat avatar tylertreat-wf avatar tylerrinnan-wf avatar

Watchers

James Cloos 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.