Context: I have a client that can connect to 3 local-network nodes to distribute query-loads and be more resilient to network/software issues. I have managed to create a -simple- watch-dog with a background-thread monitoring nodes health-status and updating the list of nodes to send the next query to. Other modules can query the watch-dog and request a suitable web3j object for next requests. This is working properly, and when I switch-off a node, requests automatically skip the non-responding local node.

Problem: The "problem" comes when trying to use web3j-generated wrapper contract objects. Each self-generated contract, due to the API design is tied for its life-time to the life-time of a web3j instance when passing a web3j reference at deploy/load instantiation time. To be able to continue using the watch-dog functionality I'm forced to create N proxy-contracts instances for each of the N local-network nodes. It works, but code looks "patchy".

Question: Is there any cleaner method to solve the problem. For example, is there a way for a single web3j instance to change underlying JSON-RPC connections transparently at runtime or for a single contract proxy to switch the underlying web3j instance/connection?

  • 1
    You should be able to use any normal HTTP load balancer setup used for web servers to balance out HTTP JSON-RPC as well. Like Nginx, to name one. I really do not understand the need to create proxy contracts at all. – Mikko Ohtamaa May 6 '20 at 12:59
  • @MikkoOhtamaa I forgot to clarify that important point. Installing Nginx or any other balancer will solve the issue, but I would prefer not to install third party software, for which I have little knowledge or time to administer when I can do that same using a couple of java classes over which I have full control. – earizon May 6 '20 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.