I'm writing a fabric client application using nodejs and the latest fabric-network library. I have setup multiple orderer nodes running in VMs and want to prioritize which orderer node to be used when submitting transactions.
I wrote my own connection profile including the above orderer nodes and let the application use it to create gateway object. Then, I'm calling transaction#submit method to execute transactions. I want to use the nearest orderer node from the application but I don't know if it's possible.
I read through fabric-skd-node source code and found that commitment procedure is done at Commit.js#send method and it pick the first healthy orderer node from the orderer list retrieved using Channel.js#getTargetCommitters method. So, my rough guess is that the first orderer node listed in connection profile is used if it's connectable.
Please correct me if I'm wrong, I'd be very grateful.
It looks like you are correct in the case that you are not using service discovery, and you client is only using nodes defined in your connection profile.
If you are using service discovery to dynamically discover network nodes then the list of orderers is randomised on each invocation to help distribute load more evenly across orderers and better handle orderer outages.
Remember that orderers will replicate transactions they receive to other orderers to maintain consistency and avoid single points of failure, so you are not avoiding transactions being sent to more distant ordering nodes.