When initiating an RPC request, it is necessary to specify the server for this call. Common scenarios include message callbacks, traffic isolation, etc.
First, add the following plugin dependency to your project
For Dubbo 2 version
The parameters for specifying IP calls revolve around the Address
object. The parameter types are as follows:
urlAddress
has the highest priority; if a target URL is specified, it will be used first. (No further matching will be performed)Specifically, if needToCreate
is specified as true
, an invoker will be automatically constructed based on the passed parameters. For addresses specified via ip (+ port), the parameters of the first address in the registry will be used as a template for creation; if no address is available, it will be automatically created based on the Dubbo protocol. If you need customized invoker creation logic, please implement the org.apache.dubbo.rpc.cluster.specifyaddress.UserSpecifiedServiceAddressBuilder
SPI interface. (This feature is only supported by Dubbo 3 implementation)
Before each request, the constructed Address
parameter should be passed to the Dubbo framework through the UserSpecifiedAddressUtil
utility class.
You must set it every time, and you must immediately make the call after setting it. If an interceptor error occurs (the removal of this value in the Dubbo framework happens during the address selection process), it is recommended to set null to avoid memory leaks in ThreadLocal, which may affect subsequent calls.