Net::TCPClient is a TCP Socket Client with built-in timeouts, retries, and logging
Find a file
2014-09-25 13:50:56 -04:00
lib/net Make SemanticLogger a soft dependency and only use it if it is already loaded 2014-09-25 07:20:43 -04:00
nbproject Rename project to net_tcp_client instead of resilient_socket to call it by what it is. And it is ready for general production use 2014-09-24 10:49:53 -04:00
test Rename project to net_tcp_client instead of resilient_socket to call it by what it is. And it is ready for general production use 2014-09-24 10:49:53 -04:00
.gitignore Add an infinite connection timeout that bypasses the async connect api 2012-11-13 13:39:39 -05:00
.ruby-gemset Rename project to net_tcp_client instead of resilient_socket to call it by what it is. And it is ready for general production use 2014-09-24 10:49:53 -04:00
.ruby-version Rename project to net_tcp_client instead of resilient_socket to call it by what it is. And it is ready for general production use 2014-09-24 10:49:53 -04:00
.travis.yml Add travis build file 2014-09-25 13:32:53 -04:00
Gemfile Add Jenkins build status 2014-09-25 13:50:56 -04:00
LICENSE.txt Add bytes written to benchmark log 2014-05-01 07:52:21 -04:00
net_tcp_client.gemspec Make SemanticLogger a soft dependency and only use it if it is already loaded 2014-09-25 07:20:43 -04:00
Rakefile Rename project to net_tcp_client instead of resilient_socket to call it by what it is. And it is ready for general production use 2014-09-24 10:49:53 -04:00
README.md Add Jenkins build status 2014-09-25 13:50:56 -04:00

net_tcp_client Build Status

Net::TCPClient is a TCP Socket Client with built-in timeouts, retries, and logging

Upgrade Notice: ResilientSocket Renamed

ResilientSocket::TCPClient has been renamed to Net::TCPClient. The new gem name is net_tcp_client.

The API is exactly the same, just with a new namespace. Please upgrade to the new net_tcp_client gem and replace all occurrences of ResilientSocket::TCPClient with Net::TCPClient in your code.

Introduction

Net::TCPClient implements resilience features that most developers wish was already included in the standard Ruby libraries.

With so many "client" libraries to servers such us memcache, MongoDB, Redis, etc. their focus is on the communication formats and messaging interactions. As a result adding resilience is usually an after thought.

More importantly the way that each client implements connection failure handling varies dramatically. The purpose of this library is to extract the best of all the socket error handling out there and create a consistent way of dealing with connection failures.

Another important feature is that the connect and read API's use timeout's to prevent a network issue from "hanging" the client program.

Net::TCPClient API

Net::TCPClient is a drop in replacement for TCPSocket when used as a client.

The initializer is the only deviation since it accepts several new options that support automatic failover, re-connect and messaging retries.

Example

Connect to a server at address localhost, and on port 3300.

Specify a custom retry interval and retry counts during connection.

require 'net/tcp_client'

Net::TCPClient.connect(
  server:                 'localhost:3300',
  connect_retry_interval: 0.1,
  connect_retry_count:    5
) do |client|
  # If the connection is lost, create a new one and retry the send
  client.retry_on_connection_failure do
    client.send('Update the database')
  end
  response = client.read(20)
  puts "Received: #{response}"
end

Dependencies

  • Ruby 1.9.3, JRuby 1.7, Rubinius 2.2, or greater

There is a soft dependency on SemanticLogger. It will use SemanticLogger only if it is already available, otherwise any other standard Ruby logger can be used.

Production Use

Net::TCPClient was built for and is being used in a high performance, highly concurrent production environment. The resilient capabilities of Net::TCPClient are put to the test on a daily basis, especially with connections over the internet between remote data centers.

Installation

gem install net_tcp_client

Meta

This project uses Semantic Versioning.

Author

Reid Morrison :: @reidmorrison

License

Copyright 2012, 2013, 2014 Reid Morrison

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.