class THTP::Client
A thrift-over-HTTP client library implementing persistent connections and extensibility via middlewares
Public Class Methods
new(service, protocol: Thrift::CompactProtocol, host: '0.0.0.0', port: nil, ssl: false, open_timeout: 1, rpc_timeout: 15, pool_size: 5, pool_timeout: 5)
click to toggle source
@param service [Class] The Thrift service whose schema to use for de/serialisation
# File lib/thtp/client.rb, line 96 def initialize(service, protocol: Thrift::CompactProtocol, host: '0.0.0.0', port: nil, ssl: false, open_timeout: 1, rpc_timeout: 15, pool_size: 5, pool_timeout: 5) uri_class = ssl ? URI::HTTPS : URI::HTTP # set up HTTP connections in a thread-safe pool connection = ConnectionPool.new(size: pool_size, timeout: pool_timeout) do Patron::Session.new( base_url: uri_class.build(host: host, port: port, path: "/#{canonical_name(service)}/"), connect_timeout: open_timeout, timeout: rpc_timeout, headers: { 'Content-Type' => Encoding.content_type(protocol), 'User-Agent' => self.class.name, }, ) end # allow middleware insertion for purposes such as instrumentation or validation @stack = MiddlewareStack.new(service, Dispatcher.new(service, connection, protocol)) extract_rpcs(service).each { |rpc| define_singleton_method(rpc, &@stack.method(rpc)) } end
Public Instance Methods
use(middleware_class, *middleware_args)
click to toggle source
delegate to RPC dispatcher stack
# File lib/thtp/client.rb, line 119 def use(middleware_class, *middleware_args) @stack.use(middleware_class, *middleware_args) end