All Projects → Workiva → thrift-nats

Workiva / thrift-nats

Licence: Apache-2.0 license
A library that adds support for using NATS as a Thrift RPC transport.

Programming Languages

go
31211 projects - #10 most used programming language
Thrift
134 projects

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].