## The logic of preferredProtocol was not user-friendly, we maybe should optimize it.

### What's the problem?
When we only use the `triple` protocol in dubbo with setting provider's register-mode as `instance`, the consumer can't find the service.


The source is in `org.apache.dubbo.config.metadata.ServiceInstanceHostPortCustomizer`, let's have a look:


```java
@Override
public void customize(ServiceInstance serviceInstance) {
    String host = null;
    int port = -1;
    // ......
    Set<URL> urls = writableMetadataService.getExportedServiceURLs();
    if (CollectionUtils.isNotEmpty(urls)) {
        ApplicationModel applicationModel = serviceInstance.getApplicationModel();
        String preferredProtocol = applicationModel.getCurrentConfig().getProtocol();
        //  The default value of preferredProtocol is dubbo.
        if (preferredProtocol != null) {
            for (URL exportedURL : urls) {
                // The protocol of exportedURL is tri
                // because of tri != dubbo, the host and port will not be assigned values.
                if (preferredProtocol.equals(exportedURL.getProtocol())) {
                    host = exportedURL.getHost();
                    port = exportedURL.getPort();
                    break;
                }
            }
        } else {
            URL url = urls.iterator().next();
            host = url.getHost();
            port = url.getPort();
        }
        // If not the port of instace > 0, the application instance will not be registered to RegistryCenter(like Nacos, Zookeeper).
        // As a result, the consumer can't find the avaliabe providers when our settging is registry-mode=instance
        if (serviceInstance instanceof DefaultServiceInstance) {
            DefaultServiceInstance instance = (DefaultServiceInstance) serviceInstance;
            instance.setHost(host);
            instance.setPort(port);
        }
    }
}
```


For the moment, if you want both consumer and provider to force using `Application Discovery` in tri protocol, just change one line config of provider as follows:


```yaml
dubbo:
  application:
    metadata-type: remote
    register-mode: instance
    protocol: tri  <==== HERE, set preferredProtocol as tri
```




### The possible solution
change the default `application-protocol` as `TRIPLE` in the future
> Why not now? Because most users are still trying to migrate from 2.0 to 3.0

```java
// => org.apache.dubbo.config.ApplicationConfig#checkDefault
protected void checkDefault() {
    super.checkDefault();
    if (protocol == null) {
        protocol = DUBBO;   // <======= HERE
    }
    // ......
}
```
In `ServiceInstanceHostPortCustomizer`, If the default protocol not exists, just try to get the first protocol and log an error log.


Related to #8666 
Related to #8599 
* (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.
 */
package org.apache.dubbo.config.metadata;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.metadata.WritableMetadataService;
import org.apache.dubbo.registry.client.DefaultServiceInstance;
import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.registry.client.ServiceInstanceCustomizer;
import org.apache.dubbo.rpc.model.ApplicationModel;
import java.util.Set;
/**
 * The {@link ServiceInstanceCustomizer} to customize the {@link ServiceInstance#getPort() port} of service instance.
 *
 * @since 2.7.5
 */
public class ServiceInstanceHostPortCustomizer implements ServiceInstanceCustomizer {
    @Override
    public void customize(ServiceInstance serviceInstance) {
        if (serviceInstance.getPort() > 0) {
            return;