001/** 002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.jboot.components.rpc; 017 018import io.jboot.app.config.annotation.ConfigModel; 019import io.jboot.utils.StrUtil; 020 021import java.util.Map; 022 023 024@ConfigModel(prefix = "jboot.rpc") 025public class JbootrpcConfig { 026 027 public static final String TYPE_DUBBO = "dubbo"; 028 public static final String TYPE_MOTAN = "motan"; 029 public static final String TYPE_LOCAL = "local"; 030 031 032 //使用的 RPC 类型 033 private String type; 034 035 036 //用于直连时的配置,直连一般只用于测试环境 037 //com.service.AAAService:127.0.0.1:8080,com.service.XXXService:127.0.0.1:8080 038 private Map<String, String> urls; 039 040 //服务的provider指定,可以通过注解 @RPCBean 指定,也可以通过此处指定,此处的配置优先于注解 041 //com.service.AAAService:providerName,com.service.XXXService:providerName 042 private Map<String, String> providers; 043 044 //服务的consumer指定,可以通过注解 @RPCInject 指定,也可以通过此处指定,此处的配置优先于注解 045 //com.service.AAAService:providerName,com.service.XXXService:providerName 046 private Map<String, String> consumers; 047 048 //当不配置的时候,默认版本号 049 private String defaultVersion = "1.0.0"; 050 051 //指定的服务的版本号 052 private Map<String, String> versions; 053 054 //当不指定的时候,默认分组 055 private String defaultGroup; 056 057 //指定的服务的分组 058 private Map<String, String> groups; 059 060 //本地自动暴露 @RPCBean 的 service 061 private boolean autoExportEnable = true; 062 063 public String getType() { 064 return type; 065 } 066 067 public void setType(String type) { 068 this.type = type; 069 } 070 071 public Map<String, String> getUrls() { 072 return urls; 073 } 074 075 public void setUrls(Map<String, String> urls) { 076 this.urls = urls; 077 } 078 079 public String getUrl(String serviceClass) { 080 return urls == null ? null : urls.get(serviceClass); 081 } 082 083 public Map<String, String> getProviders() { 084 return providers; 085 } 086 087 public void setProviders(Map<String, String> providers) { 088 this.providers = providers; 089 } 090 091 public String getProvider(String serviceClass) { 092 return providers == null ? null : providers.get(serviceClass); 093 } 094 095 public Map<String, String> getConsumers() { 096 return consumers; 097 } 098 099 public void setConsumers(Map<String, String> consumers) { 100 this.consumers = consumers; 101 } 102 103 public String getConsumer(String serviceClass) { 104 return consumers == null ? null : consumers.get(serviceClass); 105 } 106 107 public String getDefaultVersion() { 108 return defaultVersion; 109 } 110 111 public void setDefaultVersion(String defaultVersion) { 112 this.defaultVersion = defaultVersion; 113 } 114 115 public Map<String, String> getVersions() { 116 return versions; 117 } 118 119 public void setVersions(Map<String, String> versions) { 120 this.versions = versions; 121 } 122 123 public String getVersion(String className) { 124 String version = versions == null || versions.isEmpty() ? null : versions.get(className); 125 return version == null ? defaultVersion : version; 126 } 127 128 public String getDefaultGroup() { 129 return defaultGroup; 130 } 131 132 public void setDefaultGroup(String defaultGroup) { 133 this.defaultGroup = defaultGroup; 134 } 135 136 public Map<String, String> getGroups() { 137 return groups; 138 } 139 140 public void setGroups(Map<String, String> groups) { 141 this.groups = groups; 142 } 143 144 public String getGroup(String className) { 145 String group = groups == null || groups.isEmpty() ? null : groups.get(className); 146 return group == null ? defaultGroup : group; 147 } 148 149 public boolean isAutoExportEnable() { 150 return autoExportEnable; 151 } 152 153 public void setAutoExportEnable(boolean autoExportEnable) { 154 this.autoExportEnable = autoExportEnable; 155 } 156 157 public boolean isConfigOk() { 158 return StrUtil.isNotBlank(getType()); 159 } 160}