[go-steem/rpc] Release 0.2.0: Auto-Reconnect Mode and Much More

in #steem-golang8 years ago (edited)

I would like to announce go-steem/rpc version 0.2.0. I heavily refactored and extended the package.

Release Notes

The release summary can be found on GitHub, but let me demonstrate all the Kool-Aid here.

Auto-Reconnect Mode

When developing #steemwatch I ended up hitting an issue when booting the server. SteemWatch starts quickly, actually much faster than steemd. This means that by the time SteemWatch is online, the RPC endpoint is not yet exported by steemd. SteemWatch, or any other service, has to be a bit more clever about managing the connection to steemd. And this is what the auto-reconnect mode does. It transparently re-connects when the connection to steemd is lost. I decided not to bake it into SteemWatch but rather make it a part of go-steem/rpc itself.

I extended examples/voting_monitor to include auto-reconnect, optionally.

So, let us first try with steemd down and no reconnect enabled.

$ ./voting_monitor 
2016/07/07 14:55:23 ---> Dial("ws://localhost:8090")
2016/07/07 14:55:23 failed to establish TCP connection: dial tcp 127.0.0.1:8090: getsockopt: connection refused

Too bad. The process simply crashes and that's it. Auto-reconnect mode can help us here.

$ ./voting_monitor -reconnect
2016/07/07 14:55:29 ---> Dial("ws://localhost:8090")
2016/07/07 14:55:29 ---> GetConfig()
2016/07/07 14:55:29 CONNECTING [url=ws://localhost:8090]
2016/07/07 14:55:29 DISCONNECTED [url=ws://localhost:8090, err=dial tcp 127.0.0.1:8090: getsockopt: connection refused]
2016/07/07 14:55:30 CONNECTING [url=ws://localhost:8090]
2016/07/07 14:55:30 DISCONNECTED [url=ws://localhost:8090, err=dial tcp 127.0.0.1:8090: getsockopt: connection refused]
2016/07/07 14:55:32 CONNECTING [url=ws://localhost:8090]
2016/07/07 14:55:32 DISCONNECTED [url=ws://localhost:8090, err=dial tcp 127.0.0.1:8090: getsockopt: connection refused]
2016/07/07 14:55:36 CONNECTING [url=ws://localhost:8090]
2016/07/07 14:55:36 DISCONNECTED [url=ws://localhost:8090, err=dial tcp 127.0.0.1:8090: getsockopt: connection refused]
2016/07/07 14:55:44 CONNECTING [url=ws://localhost:8090]
2016/07/07 14:55:44 DISCONNECTED [url=ws://localhost:8090, err=dial tcp 127.0.0.1:8090: getsockopt: connection refused]
2016/07/07 14:56:00 CONNECTING [url=ws://localhost:8090]
2016/07/07 14:56:00 DISCONNECTED [url=ws://localhost:8090, err=dial tcp 127.0.0.1:8090: getsockopt: connection refused]
2016/07/07 14:56:30 CONNECTING [url=ws://localhost:8090]
2016/07/07 14:56:30 CONNECTED [url=ws://localhost:8090]
2016/07/07 14:56:39 ---> Entering the block processing loop (last block = 2979470)
@tuck-fheman voted for @rok-sivante/re-tuck-fheman-re-rok-sivante-re-pfunk-re-tuck-fheman-are-chemtrails-real-cia-director-john-o-brennan-seems-to-think-so-20160707t041152280z
@lafona voted for @ernio/lessons-from-a-fire-escape
@jupiter00000 voted for @true-profit/re-jupiter00000-grilled-king-salmon-piccatta-with-bleu-cheese-alfredo-wild-lobster-mushrooms-my-father-s-garden-kale-roasted-garlic-lemon-20160707t005918090z
@lafona-miner voted for @ernio/lessons-from-a-fire-escape
@lafona voted for @rok-sivante/holy-shit-steemit-is-legit-dollas-in-the-bank-holla
@patrick-g voted for @stellabelle/survival-guide-for-super-newbie-writers-steemit-edition
2016/07/07 14:56:46 DISCONNECTED [url=ws://localhost:8090, err=unexpected EOF]
2016/07/07 14:56:46 CONNECTING [url=ws://localhost:8090]
2016/07/07 14:56:46 DISCONNECTED [url=ws://localhost:8090, err=dial tcp 127.0.0.1:8090: getsockopt: connection refused]
2016/07/07 14:56:47 CONNECTING [url=ws://localhost:8090]
2016/07/07 14:56:47 DISCONNECTED [url=ws://localhost:8090, err=dial tcp 127.0.0.1:8090: getsockopt: connection refused]
2016/07/07 14:56:49 CONNECTING [url=ws://localhost:8090]
2016/07/07 14:56:49 DISCONNECTED [url=ws://localhost:8090, err=dial tcp 127.0.0.1:8090: getsockopt: connection refused]
2016/07/07 14:56:53 CONNECTING [url=ws://localhost:8090]
2016/07/07 14:56:53 DISCONNECTED [url=ws://localhost:8090, err=dial tcp 127.0.0.1:8090: getsockopt: connection refused]
^C
2016/07/07 14:56:53 Signal received, exiting...

Here steemd is down initially, then the connection is established, then steemd is killed again and the reconnecting logic kicks in again, all for free. And it is really simple to enable auto-reconnect and monitoring:

t, err := websocket.NewTransport(url,
        websocket.SetAutoReconnectEnabled(true),
        websocket.SetAutoReconnectMaxDelay(30*time.Second),
        websocket.SetMonitor(monitorChannel))

So, have fun with the package and let me know if anything is not working properly. Please open a GitHub issue any time or, even better, send a pull request directly.

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 64386.10
ETH 3142.17
USDT 1.00
SBD 3.98