com.alibaba.rocketmq.common.namesrv.NamesrvUtil Java Examples
The following examples show how to use
com.alibaba.rocketmq.common.namesrv.NamesrvUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultRequestProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetRouteInfoRequestHeader requestHeader = (GetRouteInfoRequestHeader) request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class); TopicRouteData topicRouteData = this.namesrvController.getRouteInfoManager().pickupTopicRouteData(requestHeader.getTopic()); if (topicRouteData != null) { String orderTopicConf = this.namesrvController.getKvConfigManager().getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, requestHeader.getTopic()); topicRouteData.setOrderTopicConf(orderTopicConf); byte[] content = topicRouteData.encode(); response.setBody(content); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("No topic route info in name server for the topic: " + requestHeader.getTopic() + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL)); return response; }
Example #2
Source File: NamesrvService.java From rocketmq with Apache License 2.0 | 6 votes |
@CmdTrace(cmdClazz = UpdateProjectGroupCommand.class) public boolean updateProjectGroup(String ip, String project) throws Throwable { Throwable t = null; DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt(); String namespace = NamesrvUtil.NAMESPACE_PROJECT_CONFIG; try { defaultMQAdminExt.start(); defaultMQAdminExt.createAndUpdateKvConfig(namespace, ip, project); return true; } catch (Throwable e) { logger.error(e.getMessage(), e); t = e; } finally { shutdownDefaultMQAdminExt(defaultMQAdminExt); } throw t; }
Example #3
Source File: UpdateProjectGroupCommand.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { String namespace = NamesrvUtil.NAMESPACE_PROJECT_CONFIG; String ip = commandLine.getOptionValue('i').trim(); String project = commandLine.getOptionValue('p').trim(); defaultMQAdminExt.start(); defaultMQAdminExt.createAndUpdateKvConfig(namespace, ip, project); System.out.printf("create or update kv config to namespace success.\n"); return; } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example #4
Source File: DefaultRequestProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
public RemotingCommand registerBrokerWithFilterServer(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(RegisterBrokerResponseHeader.class); final RegisterBrokerResponseHeader responseHeader = (RegisterBrokerResponseHeader) response.readCustomHeader(); final RegisterBrokerRequestHeader requestHeader = (RegisterBrokerRequestHeader) request.decodeCommandCustomHeader(RegisterBrokerRequestHeader.class); RegisterBrokerBody registerBrokerBody = new RegisterBrokerBody(); if (request.getBody() != null) { registerBrokerBody = RegisterBrokerBody.decode(request.getBody(), RegisterBrokerBody.class); } else { registerBrokerBody.getTopicConfigSerializeWrapper().getDataVersion().setCounter(new AtomicLong(0)); registerBrokerBody.getTopicConfigSerializeWrapper().getDataVersion().setTimestatmp(0); } RegisterBrokerResult result = this.namesrvController.getRouteInfoManager().registerBroker(// requestHeader.getClusterName(), // 1 requestHeader.getBrokerAddr(), // 2 requestHeader.getBrokerName(), // 3 requestHeader.getBrokerId(), // 4 requestHeader.getHaServerAddr(),// 5 registerBrokerBody.getTopicConfigSerializeWrapper(), // 6 registerBrokerBody.getFilterServerList(),// ctx.channel()// 7 ); responseHeader.setHaServerAddr(result.getHaServerAddr()); responseHeader.setMasterAddr(result.getMasterAddr()); byte[] jsonValue = this.namesrvController.getKvConfigManager().getKVListByNamespace(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG); response.setBody(jsonValue); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }
Example #5
Source File: ClusterTestRequestProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
@Override public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetRouteInfoRequestHeader requestHeader = (GetRouteInfoRequestHeader) request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class); TopicRouteData topicRouteData = this.namesrvController.getRouteInfoManager().pickupTopicRouteData(requestHeader.getTopic()); if (topicRouteData != null) { String orderTopicConf = this.namesrvController.getKvConfigManager().getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, requestHeader.getTopic()); topicRouteData.setOrderTopicConf(orderTopicConf); } else { try { topicRouteData = adminExt.examineTopicRouteInfo(requestHeader.getTopic()); } catch (Exception e) { log.info("get route info by topic from product environment failed. envName={},", productEnvName); } } if (topicRouteData != null) { byte[] content = topicRouteData.encode(); response.setBody(content); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("No topic route info in name server for the topic: " + requestHeader.getTopic() + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL)); return response; }
Example #6
Source File: NamesrvService.java From rocketmq with Apache License 2.0 | 5 votes |
@CmdTrace(cmdClazz = DeleteProjectGroupCommand.class) public boolean deleteProjectGroup(String ip, String project) throws Throwable { Throwable t = null; DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt(); String namespace = NamesrvUtil.NAMESPACE_PROJECT_CONFIG; try { if (StringUtils.isNotBlank(ip)) { defaultMQAdminExt.start(); defaultMQAdminExt.deleteKvConfig(namespace, ip); return true; } else if (StringUtils.isNotBlank(project)) { defaultMQAdminExt.start(); defaultMQAdminExt.deleteIpsByProjectGroup(project); return true; } else { throw new IllegalStateException("project or ip can not be all blank!"); } } catch (Throwable e) { logger.error(e.getMessage(), e); t = e; } finally { shutdownDefaultMQAdminExt(defaultMQAdminExt); } throw t; }
Example #7
Source File: DefaultRequestProcessor.java From rocketmq with Apache License 2.0 | 5 votes |
public RemotingCommand registerBrokerWithFilterServer(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(RegisterBrokerResponseHeader.class); final RegisterBrokerResponseHeader responseHeader = (RegisterBrokerResponseHeader) response.readCustomHeader(); final RegisterBrokerRequestHeader requestHeader = (RegisterBrokerRequestHeader) request.decodeCommandCustomHeader(RegisterBrokerRequestHeader.class); RegisterBrokerBody registerBrokerBody = new RegisterBrokerBody(); if (request.getBody() != null) { registerBrokerBody = RegisterBrokerBody.decode(request.getBody(), RegisterBrokerBody.class); } else { registerBrokerBody.getTopicConfigSerializeWrapper().getDataVersion().setCounter(new AtomicLong(0)); registerBrokerBody.getTopicConfigSerializeWrapper().getDataVersion().setTimestatmp(0); } RegisterBrokerResult result = this.namesrvController.getRouteInfoManager().registerBroker(// requestHeader.getClusterName(), // 1 requestHeader.getBrokerAddr(), // 2 requestHeader.getBrokerName(), // 3 requestHeader.getBrokerId(), // 4 requestHeader.getHaServerAddr(),// 5 registerBrokerBody.getTopicConfigSerializeWrapper(), // 6 registerBrokerBody.getFilterServerList(),// ctx.channel()// 7 ); responseHeader.setHaServerAddr(result.getHaServerAddr()); responseHeader.setMasterAddr(result.getMasterAddr()); byte[] jsonValue = this.namesrvController.getKvConfigManager().getKVListByNamespace(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG); response.setBody(jsonValue); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }
Example #8
Source File: DefaultRequestProcessor.java From rocketmq with Apache License 2.0 | 5 votes |
public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetRouteInfoRequestHeader requestHeader = (GetRouteInfoRequestHeader) request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class); TopicRouteData topicRouteData = this.namesrvController.getRouteInfoManager().pickupTopicRouteData(requestHeader.getTopic()); if (topicRouteData != null) { if (this.namesrvController.getNamesrvConfig().isOrderMessageEnable()) { String orderTopicConf = this.namesrvController.getKvConfigManager().getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, requestHeader.getTopic()); topicRouteData.setOrderTopicConf(orderTopicConf); } byte[] content = topicRouteData.encode(); response.setBody(content); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("No topic route info in name server for the topic: " + requestHeader.getTopic() + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL)); return response; }
Example #9
Source File: ClusterTestRequestProcessor.java From rocketmq with Apache License 2.0 | 5 votes |
@Override public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetRouteInfoRequestHeader requestHeader = (GetRouteInfoRequestHeader) request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class); TopicRouteData topicRouteData = this.namesrvController.getRouteInfoManager().pickupTopicRouteData(requestHeader.getTopic()); if (topicRouteData != null) { String orderTopicConf = this.namesrvController.getKvConfigManager().getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, requestHeader.getTopic()); topicRouteData.setOrderTopicConf(orderTopicConf); } else { try { topicRouteData = adminExt.examineTopicRouteInfo(requestHeader.getTopic()); } catch (Exception e) { log.info("get route info by topic from product environment failed. envName={},", productEnvName); } } if (topicRouteData != null) { byte[] content = topicRouteData.encode(); response.setBody(content); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("No topic route info in name server for the topic: " + requestHeader.getTopic() + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL)); return response; }
Example #10
Source File: DefaultRequestProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
/** * 通过topic找到路由信息 * @param ctx * @param request * @return * @throws RemotingCommandException */ public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetRouteInfoRequestHeader requestHeader = (GetRouteInfoRequestHeader) request .decodeCommandCustomHeader(GetRouteInfoRequestHeader.class); TopicRouteData topicRouteData = this.namesrvController.getRouteInfoManager().pickupTopicRouteData(requestHeader.getTopic()); if (topicRouteData != null) { String orderTopicConf = this.namesrvController.getKvConfigManager() .getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, requestHeader.getTopic()); topicRouteData.setOrderTopicConf(orderTopicConf); byte[] content = topicRouteData.encode(); response.setBody(content); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("No topic route info in name server for the topic: " + requestHeader.getTopic() + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL)); return response; }
Example #11
Source File: DeleteProjectGroupCommand.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { String namespace = NamesrvUtil.NAMESPACE_PROJECT_CONFIG; if (commandLine.hasOption("i")) { String ip = commandLine.getOptionValue('i').trim(); defaultMQAdminExt.start(); defaultMQAdminExt.deleteKvConfig(namespace, ip); System.out.printf("delete project group from namespace by server ip success.\n"); } else if (commandLine.hasOption("p")) { String project = commandLine.getOptionValue('p').trim(); defaultMQAdminExt.start(); defaultMQAdminExt.deleteIpsByProjectGroup(project); System.out.printf("delete all server ip from namespace by project group success.\n"); } else { ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options); } } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example #12
Source File: DefaultRequestProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
public RemotingCommand registerBrokerWithFilterServer(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(RegisterBrokerResponseHeader.class); final RegisterBrokerResponseHeader responseHeader = (RegisterBrokerResponseHeader) response.readCustomHeader(); final RegisterBrokerRequestHeader requestHeader = (RegisterBrokerRequestHeader) request .decodeCommandCustomHeader(RegisterBrokerRequestHeader.class); RegisterBrokerBody registerBrokerBody = new RegisterBrokerBody(); if (request.getBody() != null) { registerBrokerBody = RegisterBrokerBody.decode(request.getBody(), RegisterBrokerBody.class); } else { registerBrokerBody.getTopicConfigSerializeWrapper().getDataVersion() .setCounter(new AtomicLong(0)); registerBrokerBody.getTopicConfigSerializeWrapper().getDataVersion().setTimestatmp(0); } RegisterBrokerResult result = this.namesrvController.getRouteInfoManager().registerBroker(// requestHeader.getClusterName(), // 1 requestHeader.getBrokerAddr(), // 2 requestHeader.getBrokerName(), // 3 requestHeader.getBrokerId(), // 4 requestHeader.getHaServerAddr(), // 5 registerBrokerBody.getTopicConfigSerializeWrapper(), // 6 registerBrokerBody.getFilterServerList(), // ctx.channel()// 7 ); responseHeader.setHaServerAddr(result.getHaServerAddr()); responseHeader.setMasterAddr(result.getMasterAddr()); // 获取顺序消息 topic 列表 byte[] jsonValue = this.namesrvController.getKvConfigManager() .getKVListByNamespace(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG); response.setBody(jsonValue); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }
Example #13
Source File: DefaultMQAdminExtImpl.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
@Override public String getIpsByProjectGroup(String projectGroup) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { String namespace = NamesrvUtil.NAMESPACE_PROJECT_CONFIG; return this.mqClientInstance.getMQClientAPIImpl().getKVConfigByValue(namespace, projectGroup, 3000); }
Example #14
Source File: DefaultMQAdminExtImpl.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
@Override public void deleteIpsByProjectGroup(String projectGroup) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { String namespace = NamesrvUtil.NAMESPACE_PROJECT_CONFIG; this.mqClientInstance.getMQClientAPIImpl().deleteKVConfigByValue(namespace, projectGroup, 3000); }
Example #15
Source File: MQClientAPIImpl.java From RocketMQ-Master-analyze with Apache License 2.0 | 2 votes |
/** * 从nameserver 通过本地IP获取 ProjectGroup * * @param ip * @param timeoutMillis * @return * @throws RemotingException * @throws MQClientException * @throws InterruptedException */ public String getProjectGroupByIp(String ip, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { return getKVConfigValue(NamesrvUtil.NAMESPACE_PROJECT_CONFIG, ip, timeoutMillis); }