Java Code Examples for org.apache.rocketmq.common.protocol.body.Connection#setLanguage()
The following examples show how to use
org.apache.rocketmq.common.protocol.body.Connection#setLanguage() .
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: AdminBrokerProcessor.java From rocketmq with Apache License 2.0 | 5 votes |
private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetProducerConnectionListRequestHeader requestHeader = (GetProducerConnectionListRequestHeader)request.decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class); ProducerConnection bodydata = new ProducerConnection(); HashMap<Channel, ClientChannelInfo> channelInfoHashMap = this.brokerController.getProducerManager().getGroupChannelTable().get(requestHeader.getProducerGroup()); if (channelInfoHashMap != null) { Iterator<Map.Entry<Channel, ClientChannelInfo>> it = channelInfoHashMap.entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); connection.setClientId(info.getClientId()); connection.setLanguage(info.getLanguage()); connection.setVersion(info.getVersion()); connection.setClientAddr(RemotingHelper.parseChannelRemoteAddr(info.getChannel())); bodydata.getConnectionSet().add(connection); } byte[] body = bodydata.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("the producer group[" + requestHeader.getProducerGroup() + "] not exist"); return response; }
Example 2
Source File: AdminBrokerProcessor.java From rocketmq with Apache License 2.0 | 5 votes |
private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetProducerConnectionListRequestHeader requestHeader = (GetProducerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class); ProducerConnection bodydata = new ProducerConnection(); Map<Channel, ClientChannelInfo> channelInfoHashMap = this.brokerController.getProducerManager().getGroupChannelTable().get(requestHeader.getProducerGroup()); if (channelInfoHashMap != null) { Iterator<Map.Entry<Channel, ClientChannelInfo>> it = channelInfoHashMap.entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); connection.setClientId(info.getClientId()); connection.setLanguage(info.getLanguage()); connection.setVersion(info.getVersion()); connection.setClientAddr(RemotingHelper.parseChannelRemoteAddr(info.getChannel())); bodydata.getConnectionSet().add(connection); } byte[] body = bodydata.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("the producer group[" + requestHeader.getProducerGroup() + "] not exist"); return response; }
Example 3
Source File: AdminBrokerProcessor.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetProducerConnectionListRequestHeader requestHeader = (GetProducerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class); ProducerConnection bodydata = new ProducerConnection(); HashMap<Channel, ClientChannelInfo> channelInfoHashMap = this.brokerController.getProducerManager().getGroupChannelTable().get(requestHeader.getProducerGroup()); if (channelInfoHashMap != null) { Iterator<Map.Entry<Channel, ClientChannelInfo>> it = channelInfoHashMap.entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); connection.setClientId(info.getClientId()); connection.setLanguage(info.getLanguage()); connection.setVersion(info.getVersion()); connection.setClientAddr(RemotingHelper.parseChannelRemoteAddr(info.getChannel())); bodydata.getConnectionSet().add(connection); } byte[] body = bodydata.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("the producer group[" + requestHeader.getProducerGroup() + "] not exist"); return response; }
Example 4
Source File: AdminBrokerProcessor.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumerConnectionListRequestHeader requestHeader = (GetConsumerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class); ConsumerGroupInfo consumerGroupInfo = this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup()); if (consumerGroupInfo != null) { ConsumerConnection bodydata = new ConsumerConnection(); bodydata.setConsumeFromWhere(consumerGroupInfo.getConsumeFromWhere()); bodydata.setConsumeType(consumerGroupInfo.getConsumeType()); bodydata.setMessageModel(consumerGroupInfo.getMessageModel()); bodydata.getSubscriptionTable().putAll(consumerGroupInfo.getSubscriptionTable()); Iterator<Map.Entry<Channel, ClientChannelInfo>> it = consumerGroupInfo.getChannelInfoTable().entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); connection.setClientId(info.getClientId()); connection.setLanguage(info.getLanguage()); connection.setVersion(info.getVersion()); connection.setClientAddr(RemotingHelper.parseChannelRemoteAddr(info.getChannel())); bodydata.getConnectionSet().add(connection); } byte[] body = bodydata.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.CONSUMER_NOT_ONLINE); response.setRemark("the consumer group[" + requestHeader.getConsumerGroup() + "] not online"); return response; }
Example 5
Source File: AdminBrokerProcessor.java From DDMQ with Apache License 2.0 | 5 votes |
private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetProducerConnectionListRequestHeader requestHeader = (GetProducerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class); ProducerConnection bodydata = new ProducerConnection(); HashMap<Channel, ClientChannelInfo> channelInfoHashMap = this.brokerController.getProducerManager().getGroupChannelTable().get(requestHeader.getProducerGroup()); if (channelInfoHashMap != null) { Iterator<Map.Entry<Channel, ClientChannelInfo>> it = channelInfoHashMap.entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); connection.setClientId(info.getClientId()); connection.setLanguage(info.getLanguage()); connection.setVersion(info.getVersion()); connection.setClientAddr(RemotingHelper.parseChannelRemoteAddr(info.getChannel())); bodydata.getConnectionSet().add(connection); } byte[] body = bodydata.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("the producer group[" + requestHeader.getProducerGroup() + "] not exist"); return response; }
Example 6
Source File: AdminBrokerProcessor.java From DDMQ with Apache License 2.0 | 5 votes |
private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumerConnectionListRequestHeader requestHeader = (GetConsumerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class); ConsumerGroupInfo consumerGroupInfo = this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup()); if (consumerGroupInfo != null) { ConsumerConnection bodydata = new ConsumerConnection(); bodydata.setConsumeFromWhere(consumerGroupInfo.getConsumeFromWhere()); bodydata.setConsumeType(consumerGroupInfo.getConsumeType()); bodydata.setMessageModel(consumerGroupInfo.getMessageModel()); bodydata.getSubscriptionTable().putAll(consumerGroupInfo.getSubscriptionTable()); Iterator<Map.Entry<Channel, ClientChannelInfo>> it = consumerGroupInfo.getChannelInfoTable().entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); connection.setClientId(info.getClientId()); connection.setLanguage(info.getLanguage()); connection.setVersion(info.getVersion()); connection.setClientAddr(RemotingHelper.parseChannelRemoteAddr(info.getChannel())); bodydata.getConnectionSet().add(connection); } byte[] body = bodydata.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.CONSUMER_NOT_ONLINE); response.setRemark("the consumer group[" + requestHeader.getConsumerGroup() + "] not online"); return response; }
Example 7
Source File: AdminBrokerProcessor.java From DDMQ with Apache License 2.0 | 5 votes |
private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumerConnectionListRequestHeader requestHeader = (GetConsumerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class); ConsumerGroupInfo consumerGroupInfo = this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup()); if (consumerGroupInfo != null) { ConsumerConnection bodydata = new ConsumerConnection(); bodydata.setConsumeFromWhere(consumerGroupInfo.getConsumeFromWhere()); bodydata.setConsumeType(consumerGroupInfo.getConsumeType()); bodydata.setMessageModel(consumerGroupInfo.getMessageModel()); bodydata.getSubscriptionTable().putAll(consumerGroupInfo.getSubscriptionTable()); Iterator<Map.Entry<Channel, ClientChannelInfo>> it = consumerGroupInfo.getChannelInfoTable().entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); connection.setClientId(info.getClientId()); connection.setLanguage(info.getLanguage()); connection.setVersion(info.getVersion()); connection.setClientAddr(RemotingHelper.parseChannelRemoteAddr(info.getChannel())); bodydata.getConnectionSet().add(connection); } byte[] body = bodydata.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.CONSUMER_NOT_ONLINE); response.setRemark("the consumer group[" + requestHeader.getConsumerGroup() + "] not online"); return response; }
Example 8
Source File: AdminBrokerProcessor.java From rocketmq with Apache License 2.0 | 5 votes |
private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumerConnectionListRequestHeader requestHeader = (GetConsumerConnectionListRequestHeader)request.decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class); ConsumerGroupInfo consumerGroupInfo = this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup()); if (consumerGroupInfo != null) { ConsumerConnection bodydata = new ConsumerConnection(); bodydata.setConsumeFromWhere(consumerGroupInfo.getConsumeFromWhere()); bodydata.setConsumeType(consumerGroupInfo.getConsumeType()); bodydata.setMessageModel(consumerGroupInfo.getMessageModel()); bodydata.getSubscriptionTable().putAll(consumerGroupInfo.getSubscriptionTable()); Iterator<Map.Entry<Channel, ClientChannelInfo>> it = consumerGroupInfo.getChannelInfoTable().entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); connection.setClientId(info.getClientId()); connection.setLanguage(info.getLanguage()); connection.setVersion(info.getVersion()); connection.setClientAddr(RemotingHelper.parseChannelRemoteAddr(info.getChannel())); bodydata.getConnectionSet().add(connection); } byte[] body = bodydata.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.CONSUMER_NOT_ONLINE); response.setRemark("the consumer group[" + requestHeader.getConsumerGroup() + "] not online"); return response; }
Example 9
Source File: AdminBrokerProcessor.java From rocketmq-read with Apache License 2.0 | 5 votes |
/** * 获取全部生产者的连接的列表 * @param ctx ; * @param request ; * @return ; * @throws RemotingCommandException ; */ private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetProducerConnectionListRequestHeader requestHeader = (GetProducerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class); ProducerConnection bodydata = new ProducerConnection(); HashMap<Channel, ClientChannelInfo> channelInfoHashMap = this.brokerController.getProducerManager().getGroupChannelTable().get(requestHeader.getProducerGroup()); if (channelInfoHashMap != null) { Iterator<Map.Entry<Channel, ClientChannelInfo>> it = channelInfoHashMap.entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); connection.setClientId(info.getClientId()); connection.setLanguage(info.getLanguage()); connection.setVersion(info.getVersion()); connection.setClientAddr(RemotingHelper.parseChannelRemoteAddr(info.getChannel())); bodydata.getConnectionSet().add(connection); } byte[] body = bodydata.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("the producer group[" + requestHeader.getProducerGroup() + "] not exist"); return response; }
Example 10
Source File: AdminBrokerProcessor.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetProducerConnectionListRequestHeader requestHeader = (GetProducerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class); // 构建生产者连接信息 ProducerConnection bodydata = new ProducerConnection(); HashMap<Channel, ClientChannelInfo> channelInfoHashMap = // 按生产组从缓存中获取生产者连接列表信息=》 this.brokerController.getProducerManager().getGroupChannelTable().get(requestHeader.getProducerGroup()); if (channelInfoHashMap != null) { // 遍历channelInfo信息 Iterator<Map.Entry<Channel, ClientChannelInfo>> it = channelInfoHashMap.entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); // 构建生产者连接 Connection connection = new Connection(); connection.setClientId(info.getClientId()); connection.setLanguage(info.getLanguage()); connection.setVersion(info.getVersion()); connection.setClientAddr(RemotingHelper.parseChannelRemoteAddr(info.getChannel())); bodydata.getConnectionSet().add(connection); } byte[] body = bodydata.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("the producer group[" + requestHeader.getProducerGroup() + "] not exist"); return response; }
Example 11
Source File: AdminBrokerProcessor.java From DDMQ with Apache License 2.0 | 5 votes |
private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetProducerConnectionListRequestHeader requestHeader = (GetProducerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class); ProducerConnection bodydata = new ProducerConnection(); HashMap<Channel, ClientChannelInfo> channelInfoHashMap = this.brokerController.getProducerManager().getGroupChannelTable().get(requestHeader.getProducerGroup()); if (channelInfoHashMap != null) { Iterator<Map.Entry<Channel, ClientChannelInfo>> it = channelInfoHashMap.entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); connection.setClientId(info.getClientId()); connection.setLanguage(info.getLanguage()); connection.setVersion(info.getVersion()); connection.setClientAddr(RemotingHelper.parseChannelRemoteAddr(info.getChannel())); bodydata.getConnectionSet().add(connection); } byte[] body = bodydata.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("the producer group[" + requestHeader.getProducerGroup() + "] not exist"); return response; }
Example 12
Source File: MonitorServiceTest.java From rocketmq-read with Apache License 2.0 | 4 votes |
@BeforeClass public static void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException, MQBrokerException { monitorConfig = new MonitorConfig(); monitorListener = new DefaultMonitorListener(); defaultMQPullConsumer = mock(DefaultMQPullConsumer.class); defaultMQPushConsumer = mock(DefaultMQPushConsumer.class); mQClientAPIImpl = mock(MQClientAPIImpl.class); defaultMQAdminExt = new DefaultMQAdminExt(); defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000); monitorService = new MonitorService(monitorConfig, monitorListener, null); Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance"); field.setAccessible(true); field.set(defaultMQAdminExtImpl, mqClientInstance); field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl"); field.setAccessible(true); field.set(mqClientInstance, mQClientAPIImpl); field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl"); field.setAccessible(true); field.set(defaultMQAdminExt, defaultMQAdminExtImpl); field = MonitorService.class.getDeclaredField("defaultMQAdminExt"); field.setAccessible(true); field.set(monitorService, defaultMQAdminExt); field = MonitorService.class.getDeclaredField("defaultMQPullConsumer"); field.setAccessible(true); field.set(monitorService, defaultMQPullConsumer); field = MonitorService.class.getDeclaredField("defaultMQPushConsumer"); field.setAccessible(true); field.set(monitorService, defaultMQPushConsumer); TopicList topicList = new TopicList(); Set<String> topicSet = new HashSet<>(); topicSet.add("topic_one"); topicSet.add("topic_two"); topicList.setTopicList(topicSet); when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList); TopicRouteData topicRouteData = new TopicRouteData(); List<BrokerData> brokerDatas = new ArrayList<>(); HashMap<Long, String> brokerAddrs = new HashMap<>(); brokerAddrs.put(1234l, "127.0.0.1:10911"); BrokerData brokerData = new BrokerData(); brokerData.setCluster("default-cluster"); brokerData.setBrokerName("default-broker"); brokerData.setBrokerAddrs(brokerAddrs); brokerDatas.add(brokerData); topicRouteData.setBrokerDatas(brokerDatas); topicRouteData.setQueueDatas(new ArrayList<QueueData>()); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData); ConsumeStats consumeStats = new ConsumeStats(); consumeStats.setConsumeTps(1234); MessageQueue messageQueue = new MessageQueue(); OffsetWrapper offsetWrapper = new OffsetWrapper(); HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>(); stats.put(messageQueue, offsetWrapper); consumeStats.setOffsetTable(stats); when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats); ConsumerConnection consumerConnection = new ConsumerConnection(); consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY); consumerConnection.setMessageModel(MessageModel.CLUSTERING); HashSet<Connection> connections = new HashSet<>(); Connection connection = new Connection(); connection.setClientId("client_id"); connection.setClientAddr("127.0.0.1:109111"); connection.setLanguage(LanguageCode.JAVA); connection.setVersion(MQVersion.Version.V4_0_0_SNAPSHOT.ordinal()); connections.add(connection); consumerConnection.setConnectionSet(connections); consumerConnection.setSubscriptionTable(new ConcurrentHashMap<String, SubscriptionData>()); consumerConnection.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); when(mQClientAPIImpl.getConsumerConnectionList(anyString(), anyString(), anyLong())).thenReturn(consumerConnection); ConsumerRunningInfo consumerRunningInfo = new ConsumerRunningInfo(); consumerRunningInfo.setJstack("test"); consumerRunningInfo.setMqTable(new TreeMap<MessageQueue, ProcessQueueInfo>()); consumerRunningInfo.setStatusTable(new TreeMap<String, ConsumeStatus>()); consumerRunningInfo.setSubscriptionSet(new TreeSet<SubscriptionData>()); Properties properties = new Properties(); properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, CONSUME_ACTIVELY); properties.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, System.currentTimeMillis()); consumerRunningInfo.setProperties(properties); when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo); }
Example 13
Source File: AdminBrokerProcessor.java From rocketmq-read with Apache License 2.0 | 4 votes |
/** * 获取消费者的连接列表 * @param ctx ; * @param request ; * @return ; * @throws RemotingCommandException ; */ private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumerConnectionListRequestHeader requestHeader = (GetConsumerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class); ConsumerGroupInfo consumerGroupInfo = this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup()); if (consumerGroupInfo != null) { ConsumerConnection bodydata = new ConsumerConnection(); bodydata.setConsumeFromWhere(consumerGroupInfo.getConsumeFromWhere()); bodydata.setConsumeType(consumerGroupInfo.getConsumeType()); bodydata.setMessageModel(consumerGroupInfo.getMessageModel()); bodydata.getSubscriptionTable().putAll(consumerGroupInfo.getSubscriptionTable()); /* * 连接管理 */ Iterator<Map.Entry<Channel, ClientChannelInfo>> it = consumerGroupInfo.getChannelInfoTable().entrySet().iterator(); while (it.hasNext()) { System.out.println(1); ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); connection.setClientId(info.getClientId()); connection.setLanguage(info.getLanguage()); connection.setVersion(info.getVersion()); connection.setClientAddr(RemotingHelper.parseChannelRemoteAddr(info.getChannel())); bodydata.getConnectionSet().add(connection); } byte[] body = bodydata.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.CONSUMER_NOT_ONLINE); response.setRemark("the consumer group[" + requestHeader.getConsumerGroup() + "] not online"); return response; }
Example 14
Source File: MonitorServiceTest.java From rocketmq with Apache License 2.0 | 4 votes |
@BeforeClass public static void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException, MQBrokerException { monitorConfig = new MonitorConfig(); monitorListener = new DefaultMonitorListener(); defaultMQPullConsumer = mock(DefaultMQPullConsumer.class); defaultMQPushConsumer = mock(DefaultMQPushConsumer.class); mQClientAPIImpl = mock(MQClientAPIImpl.class); defaultMQAdminExt = new DefaultMQAdminExt(); defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000); monitorService = new MonitorService(monitorConfig, monitorListener, null); Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance"); field.setAccessible(true); field.set(defaultMQAdminExtImpl, mqClientInstance); field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl"); field.setAccessible(true); field.set(mqClientInstance, mQClientAPIImpl); field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl"); field.setAccessible(true); field.set(defaultMQAdminExt, defaultMQAdminExtImpl); field = MonitorService.class.getDeclaredField("defaultMQAdminExt"); field.setAccessible(true); field.set(monitorService, defaultMQAdminExt); field = MonitorService.class.getDeclaredField("defaultMQPullConsumer"); field.setAccessible(true); field.set(monitorService, defaultMQPullConsumer); field = MonitorService.class.getDeclaredField("defaultMQPushConsumer"); field.setAccessible(true); field.set(monitorService, defaultMQPushConsumer); TopicList topicList = new TopicList(); Set<String> topicSet = new HashSet<>(); topicSet.add("topic_one"); topicSet.add("topic_two"); topicList.setTopicList(topicSet); when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList); TopicRouteData topicRouteData = new TopicRouteData(); List<BrokerData> brokerDatas = new ArrayList<>(); HashMap<Long, String> brokerAddrs = new HashMap<>(); brokerAddrs.put(1234l, "127.0.0.1:10911"); BrokerData brokerData = new BrokerData(); brokerData.setCluster("default-cluster"); brokerData.setBrokerName("default-broker"); brokerData.setBrokerAddrs(brokerAddrs); brokerDatas.add(brokerData); topicRouteData.setBrokerDatas(brokerDatas); topicRouteData.setQueueDatas(new ArrayList<QueueData>()); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData); ConsumeStats consumeStats = new ConsumeStats(); consumeStats.setConsumeTps(1234); MessageQueue messageQueue = new MessageQueue(); OffsetWrapper offsetWrapper = new OffsetWrapper(); HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>(); stats.put(messageQueue, offsetWrapper); consumeStats.setOffsetTable(stats); when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats); ConsumerConnection consumerConnection = new ConsumerConnection(); consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY); consumerConnection.setMessageModel(MessageModel.CLUSTERING); HashSet<Connection> connections = new HashSet<>(); Connection connection = new Connection(); connection.setClientId("client_id"); connection.setClientAddr("127.0.0.1:109111"); connection.setLanguage(LanguageCode.JAVA); connection.setVersion(MQVersion.Version.V4_0_0_SNAPSHOT.ordinal()); connections.add(connection); consumerConnection.setConnectionSet(connections); consumerConnection.setSubscriptionTable(new ConcurrentHashMap<String, SubscriptionData>()); consumerConnection.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); when(mQClientAPIImpl.getConsumerConnectionList(anyString(), anyString(), anyLong())).thenReturn(consumerConnection); ConsumerRunningInfo consumerRunningInfo = new ConsumerRunningInfo(); consumerRunningInfo.setJstack("test"); consumerRunningInfo.setMqTable(new TreeMap<MessageQueue, ProcessQueueInfo>()); consumerRunningInfo.setStatusTable(new TreeMap<String, ConsumeStatus>()); consumerRunningInfo.setSubscriptionSet(new TreeSet<SubscriptionData>()); Properties properties = new Properties(); properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, CONSUME_ACTIVELY); properties.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, System.currentTimeMillis()); consumerRunningInfo.setProperties(properties); when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo); }
Example 15
Source File: MonitorServiceTest.java From rocketmq-4.3.0 with Apache License 2.0 | 4 votes |
@BeforeClass public static void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException, MQBrokerException { monitorConfig = new MonitorConfig(); monitorListener = new DefaultMonitorListener(); defaultMQPullConsumer = mock(DefaultMQPullConsumer.class); defaultMQPushConsumer = mock(DefaultMQPushConsumer.class); mQClientAPIImpl = mock(MQClientAPIImpl.class); defaultMQAdminExt = new DefaultMQAdminExt(); defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000); monitorService = new MonitorService(monitorConfig, monitorListener, null); Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance"); field.setAccessible(true); field.set(defaultMQAdminExtImpl, mqClientInstance); field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl"); field.setAccessible(true); field.set(mqClientInstance, mQClientAPIImpl); field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl"); field.setAccessible(true); field.set(defaultMQAdminExt, defaultMQAdminExtImpl); field = MonitorService.class.getDeclaredField("defaultMQAdminExt"); field.setAccessible(true); field.set(monitorService, defaultMQAdminExt); field = MonitorService.class.getDeclaredField("defaultMQPullConsumer"); field.setAccessible(true); field.set(monitorService, defaultMQPullConsumer); field = MonitorService.class.getDeclaredField("defaultMQPushConsumer"); field.setAccessible(true); field.set(monitorService, defaultMQPushConsumer); TopicList topicList = new TopicList(); Set<String> topicSet = new HashSet<>(); topicSet.add("topic_one"); topicSet.add("topic_two"); topicList.setTopicList(topicSet); when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList); TopicRouteData topicRouteData = new TopicRouteData(); List<BrokerData> brokerDatas = new ArrayList<>(); HashMap<Long, String> brokerAddrs = new HashMap<>(); brokerAddrs.put(1234l, "127.0.0.1:10911"); BrokerData brokerData = new BrokerData(); brokerData.setCluster("default-cluster"); brokerData.setBrokerName("default-broker"); brokerData.setBrokerAddrs(brokerAddrs); brokerDatas.add(brokerData); topicRouteData.setBrokerDatas(brokerDatas); topicRouteData.setQueueDatas(new ArrayList<QueueData>()); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData); ConsumeStats consumeStats = new ConsumeStats(); consumeStats.setConsumeTps(1234); MessageQueue messageQueue = new MessageQueue(); OffsetWrapper offsetWrapper = new OffsetWrapper(); HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>(); stats.put(messageQueue, offsetWrapper); consumeStats.setOffsetTable(stats); when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats); ConsumerConnection consumerConnection = new ConsumerConnection(); consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY); consumerConnection.setMessageModel(MessageModel.CLUSTERING); HashSet<Connection> connections = new HashSet<>(); Connection connection = new Connection(); connection.setClientId("client_id"); connection.setClientAddr("127.0.0.1:109111"); connection.setLanguage(LanguageCode.JAVA); connection.setVersion(MQVersion.Version.V4_0_0_SNAPSHOT.ordinal()); connections.add(connection); consumerConnection.setConnectionSet(connections); consumerConnection.setSubscriptionTable(new ConcurrentHashMap<String, SubscriptionData>()); consumerConnection.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); when(mQClientAPIImpl.getConsumerConnectionList(anyString(), anyString(), anyLong())).thenReturn(consumerConnection); ConsumerRunningInfo consumerRunningInfo = new ConsumerRunningInfo(); consumerRunningInfo.setJstack("test"); consumerRunningInfo.setMqTable(new TreeMap<MessageQueue, ProcessQueueInfo>()); consumerRunningInfo.setStatusTable(new TreeMap<String, ConsumeStatus>()); consumerRunningInfo.setSubscriptionSet(new TreeSet<SubscriptionData>()); Properties properties = new Properties(); properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, CONSUME_ACTIVELY); properties.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, System.currentTimeMillis()); consumerRunningInfo.setProperties(properties); when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo); }
Example 16
Source File: MonitorServiceTest.java From DDMQ with Apache License 2.0 | 4 votes |
@BeforeClass public static void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException, MQBrokerException { monitorConfig = new MonitorConfig(); monitorListener = new DefaultMonitorListener(); defaultMQPullConsumer = mock(DefaultMQPullConsumer.class); defaultMQPushConsumer = mock(DefaultMQPushConsumer.class); mQClientAPIImpl = mock(MQClientAPIImpl.class); defaultMQAdminExt = new DefaultMQAdminExt(); defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000); monitorService = new MonitorService(monitorConfig, monitorListener, null); Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance"); field.setAccessible(true); field.set(defaultMQAdminExtImpl, mqClientInstance); field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl"); field.setAccessible(true); field.set(mqClientInstance, mQClientAPIImpl); field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl"); field.setAccessible(true); field.set(defaultMQAdminExt, defaultMQAdminExtImpl); field = MonitorService.class.getDeclaredField("defaultMQAdminExt"); field.setAccessible(true); field.set(monitorService, defaultMQAdminExt); field = MonitorService.class.getDeclaredField("defaultMQPullConsumer"); field.setAccessible(true); field.set(monitorService, defaultMQPullConsumer); field = MonitorService.class.getDeclaredField("defaultMQPushConsumer"); field.setAccessible(true); field.set(monitorService, defaultMQPushConsumer); TopicList topicList = new TopicList(); Set<String> topicSet = new HashSet<>(); topicSet.add("topic_one"); topicSet.add("topic_two"); topicList.setTopicList(topicSet); when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList); TopicRouteData topicRouteData = new TopicRouteData(); List<BrokerData> brokerDatas = new ArrayList<>(); HashMap<Long, String> brokerAddrs = new HashMap<>(); brokerAddrs.put(1234l, "127.0.0.1:10911"); BrokerData brokerData = new BrokerData(); brokerData.setCluster("default-cluster"); brokerData.setBrokerName("default-broker"); brokerData.setBrokerAddrs(brokerAddrs); brokerDatas.add(brokerData); topicRouteData.setBrokerDatas(brokerDatas); topicRouteData.setQueueDatas(new ArrayList<QueueData>()); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData); ConsumeStats consumeStats = new ConsumeStats(); consumeStats.setConsumeTps(1234); MessageQueue messageQueue = new MessageQueue(); OffsetWrapper offsetWrapper = new OffsetWrapper(); HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>(); stats.put(messageQueue, offsetWrapper); consumeStats.setOffsetTable(stats); when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats); ConsumerConnection consumerConnection = new ConsumerConnection(); consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY); consumerConnection.setMessageModel(MessageModel.CLUSTERING); HashSet<Connection> connections = new HashSet<>(); Connection connection = new Connection(); connection.setClientId("client_id"); connection.setClientAddr("127.0.0.1:109111"); connection.setLanguage(LanguageCode.JAVA); connection.setVersion(MQVersion.Version.V4_0_0_SNAPSHOT.ordinal()); connections.add(connection); consumerConnection.setConnectionSet(connections); consumerConnection.setSubscriptionTable(new ConcurrentHashMap<String, SubscriptionData>()); consumerConnection.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); when(mQClientAPIImpl.getConsumerConnectionList(anyString(), anyString(), anyLong())).thenReturn(consumerConnection); ConsumerRunningInfo consumerRunningInfo = new ConsumerRunningInfo(); consumerRunningInfo.setJstack("test"); consumerRunningInfo.setMqTable(new TreeMap<MessageQueue, ProcessQueueInfo>()); consumerRunningInfo.setStatusTable(new TreeMap<String, ConsumeStatus>()); consumerRunningInfo.setSubscriptionSet(new TreeSet<SubscriptionData>()); Properties properties = new Properties(); properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, CONSUME_ACTIVELY); properties.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, System.currentTimeMillis()); consumerRunningInfo.setProperties(properties); when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo); }
Example 17
Source File: AdminBrokerProcessor.java From rocketmq-4.3.0 with Apache License 2.0 | 4 votes |
private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumerConnectionListRequestHeader requestHeader = (GetConsumerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class); // 获取消费组信息 ConsumerGroupInfo consumerGroupInfo = this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup()); if (consumerGroupInfo != null) { // 构建消费者连接信息 ConsumerConnection bodydata = new ConsumerConnection(); bodydata.setConsumeFromWhere(consumerGroupInfo.getConsumeFromWhere()); bodydata.setConsumeType(consumerGroupInfo.getConsumeType()); bodydata.setMessageModel(consumerGroupInfo.getMessageModel()); bodydata.getSubscriptionTable().putAll(consumerGroupInfo.getSubscriptionTable()); // 遍历消费组信息中的客户端连接信息 Iterator<Map.Entry<Channel, ClientChannelInfo>> it = consumerGroupInfo.getChannelInfoTable().entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); // 构建客户端连接 Connection connection = new Connection(); connection.setClientId(info.getClientId()); connection.setLanguage(info.getLanguage()); connection.setVersion(info.getVersion()); connection.setClientAddr(RemotingHelper.parseChannelRemoteAddr(info.getChannel())); bodydata.getConnectionSet().add(connection); } byte[] body = bodydata.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.CONSUMER_NOT_ONLINE); response.setRemark("the consumer group[" + requestHeader.getConsumerGroup() + "] not online"); return response; }
Example 18
Source File: MonitorServiceTest.java From DDMQ with Apache License 2.0 | 4 votes |
@BeforeClass public static void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException, MQBrokerException { monitorConfig = new MonitorConfig(); monitorListener = new DefaultMonitorListener(); defaultMQPullConsumer = mock(DefaultMQPullConsumer.class); defaultMQPushConsumer = mock(DefaultMQPushConsumer.class); mQClientAPIImpl = mock(MQClientAPIImpl.class); defaultMQAdminExt = new DefaultMQAdminExt(); defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000); monitorService = new MonitorService(monitorConfig, monitorListener, null); Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance"); field.setAccessible(true); field.set(defaultMQAdminExtImpl, mqClientInstance); field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl"); field.setAccessible(true); field.set(mqClientInstance, mQClientAPIImpl); field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl"); field.setAccessible(true); field.set(defaultMQAdminExt, defaultMQAdminExtImpl); field = MonitorService.class.getDeclaredField("defaultMQAdminExt"); field.setAccessible(true); field.set(monitorService, defaultMQAdminExt); field = MonitorService.class.getDeclaredField("defaultMQPullConsumer"); field.setAccessible(true); field.set(monitorService, defaultMQPullConsumer); field = MonitorService.class.getDeclaredField("defaultMQPushConsumer"); field.setAccessible(true); field.set(monitorService, defaultMQPushConsumer); TopicList topicList = new TopicList(); Set<String> topicSet = new HashSet<>(); topicSet.add("topic_one"); topicSet.add("topic_two"); topicList.setTopicList(topicSet); when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList); TopicRouteData topicRouteData = new TopicRouteData(); List<BrokerData> brokerDatas = new ArrayList<>(); HashMap<Long, String> brokerAddrs = new HashMap<>(); brokerAddrs.put(1234l, "127.0.0.1:10911"); BrokerData brokerData = new BrokerData(); brokerData.setCluster("default-cluster"); brokerData.setBrokerName("default-broker"); brokerData.setBrokerAddrs(brokerAddrs); brokerDatas.add(brokerData); topicRouteData.setBrokerDatas(brokerDatas); topicRouteData.setQueueDatas(new ArrayList<QueueData>()); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData); ConsumeStats consumeStats = new ConsumeStats(); consumeStats.setConsumeTps(1234); MessageQueue messageQueue = new MessageQueue(); OffsetWrapper offsetWrapper = new OffsetWrapper(); HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>(); stats.put(messageQueue, offsetWrapper); consumeStats.setOffsetTable(stats); when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats); ConsumerConnection consumerConnection = new ConsumerConnection(); consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY); consumerConnection.setMessageModel(MessageModel.CLUSTERING); HashSet<Connection> connections = new HashSet<>(); Connection connection = new Connection(); connection.setClientId("client_id"); connection.setClientAddr("127.0.0.1:109111"); connection.setLanguage(LanguageCode.JAVA); connection.setVersion(MQVersion.Version.V4_0_0_SNAPSHOT.ordinal()); connections.add(connection); consumerConnection.setConnectionSet(connections); consumerConnection.setSubscriptionTable(new ConcurrentHashMap<String, SubscriptionData>()); consumerConnection.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); when(mQClientAPIImpl.getConsumerConnectionList(anyString(), anyString(), anyLong())).thenReturn(consumerConnection); ConsumerRunningInfo consumerRunningInfo = new ConsumerRunningInfo(); consumerRunningInfo.setJstack("test"); consumerRunningInfo.setMqTable(new TreeMap<MessageQueue, ProcessQueueInfo>()); consumerRunningInfo.setStatusTable(new TreeMap<String, ConsumeStatus>()); consumerRunningInfo.setSubscriptionSet(new TreeSet<SubscriptionData>()); Properties properties = new Properties(); properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, CONSUME_ACTIVELY); properties.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, System.currentTimeMillis()); consumerRunningInfo.setProperties(properties); when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo); }
Example 19
Source File: MonitorServiceTest.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 4 votes |
@BeforeClass public static void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException, MQBrokerException { monitorConfig = new MonitorConfig(); monitorListener = new DefaultMonitorListener(); defaultMQPullConsumer = mock(DefaultMQPullConsumer.class); defaultMQPushConsumer = mock(DefaultMQPushConsumer.class); mQClientAPIImpl = mock(MQClientAPIImpl.class); defaultMQAdminExt = new DefaultMQAdminExt(); defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000); monitorService = new MonitorService(monitorConfig, monitorListener, null); Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance"); field.setAccessible(true); field.set(defaultMQAdminExtImpl, mqClientInstance); field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl"); field.setAccessible(true); field.set(mqClientInstance, mQClientAPIImpl); field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl"); field.setAccessible(true); field.set(defaultMQAdminExt, defaultMQAdminExtImpl); field = MonitorService.class.getDeclaredField("defaultMQAdminExt"); field.setAccessible(true); field.set(monitorService, defaultMQAdminExt); field = MonitorService.class.getDeclaredField("defaultMQPullConsumer"); field.setAccessible(true); field.set(monitorService, defaultMQPullConsumer); field = MonitorService.class.getDeclaredField("defaultMQPushConsumer"); field.setAccessible(true); field.set(monitorService, defaultMQPushConsumer); TopicList topicList = new TopicList(); Set<String> topicSet = new HashSet<>(); topicSet.add("topic_one"); topicSet.add("topic_two"); topicList.setTopicList(topicSet); when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList); TopicRouteData topicRouteData = new TopicRouteData(); List<BrokerData> brokerDatas = new ArrayList<>(); HashMap<Long, String> brokerAddrs = new HashMap<>(); brokerAddrs.put(1234l, "127.0.0.1:10911"); BrokerData brokerData = new BrokerData(); brokerData.setCluster("default-cluster"); brokerData.setBrokerName("default-broker"); brokerData.setBrokerAddrs(brokerAddrs); brokerDatas.add(brokerData); topicRouteData.setBrokerDatas(brokerDatas); topicRouteData.setQueueDatas(new ArrayList<QueueData>()); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData); ConsumeStats consumeStats = new ConsumeStats(); consumeStats.setConsumeTps(1234); MessageQueue messageQueue = new MessageQueue(); OffsetWrapper offsetWrapper = new OffsetWrapper(); HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>(); stats.put(messageQueue, offsetWrapper); consumeStats.setOffsetTable(stats); when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats); ConsumerConnection consumerConnection = new ConsumerConnection(); consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY); consumerConnection.setMessageModel(MessageModel.CLUSTERING); HashSet<Connection> connections = new HashSet<>(); Connection connection = new Connection(); connection.setClientId("client_id"); connection.setClientAddr("127.0.0.1:109111"); connection.setLanguage(LanguageCode.JAVA); connection.setVersion(MQVersion.Version.V4_0_0_SNAPSHOT.ordinal()); connections.add(connection); consumerConnection.setConnectionSet(connections); consumerConnection.setSubscriptionTable(new ConcurrentHashMap<String, SubscriptionData>()); consumerConnection.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); when(mQClientAPIImpl.getConsumerConnectionList(anyString(), anyString(), anyLong())).thenReturn(consumerConnection); ConsumerRunningInfo consumerRunningInfo = new ConsumerRunningInfo(); consumerRunningInfo.setJstack("test"); consumerRunningInfo.setMqTable(new TreeMap<MessageQueue, ProcessQueueInfo>()); consumerRunningInfo.setStatusTable(new TreeMap<String, ConsumeStatus>()); consumerRunningInfo.setSubscriptionSet(new TreeSet<SubscriptionData>()); Properties properties = new Properties(); properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, CONSUME_ACTIVELY); properties.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, System.currentTimeMillis()); consumerRunningInfo.setProperties(properties); when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo); }
Example 20
Source File: MonitorServiceTest.java From rocketmq with Apache License 2.0 | 4 votes |
@BeforeClass public static void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException, MQBrokerException { monitorConfig = new MonitorConfig(); monitorListener = new DefaultMonitorListener(); defaultMQPullConsumer = mock(DefaultMQPullConsumer.class); defaultMQPushConsumer = mock(DefaultMQPushConsumer.class); mQClientAPIImpl = mock(MQClientAPIImpl.class); defaultMQAdminExt = new DefaultMQAdminExt(); defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000); monitorService = new MonitorService(monitorConfig, monitorListener, null); Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance"); field.setAccessible(true); field.set(defaultMQAdminExtImpl, mqClientInstance); field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl"); field.setAccessible(true); field.set(mqClientInstance, mQClientAPIImpl); field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl"); field.setAccessible(true); field.set(defaultMQAdminExt, defaultMQAdminExtImpl); field = MonitorService.class.getDeclaredField("defaultMQAdminExt"); field.setAccessible(true); field.set(monitorService, defaultMQAdminExt); field = MonitorService.class.getDeclaredField("defaultMQPullConsumer"); field.setAccessible(true); field.set(monitorService, defaultMQPullConsumer); field = MonitorService.class.getDeclaredField("defaultMQPushConsumer"); field.setAccessible(true); field.set(monitorService, defaultMQPushConsumer); TopicList topicList = new TopicList(); Set<String> topicSet = new HashSet<>(); topicSet.add("topic_one"); topicSet.add("topic_two"); topicList.setTopicList(topicSet); when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList); TopicRouteData topicRouteData = new TopicRouteData(); List<BrokerData> brokerDatas = new ArrayList<>(); HashMap<Long, String> brokerAddrs = new HashMap<>(); brokerAddrs.put(1234l, "127.0.0.1:10911"); BrokerData brokerData = new BrokerData(); brokerData.setCluster("default-cluster"); brokerData.setBrokerName("default-broker"); brokerData.setBrokerAddrs(brokerAddrs); brokerDatas.add(brokerData); topicRouteData.setBrokerDatas(brokerDatas); topicRouteData.setQueueDatas(new ArrayList<QueueData>()); topicRouteData.setFilterServerTable(new HashMap<String, List<String>>()); when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData); ConsumeStats consumeStats = new ConsumeStats(); consumeStats.setConsumeTps(1234); MessageQueue messageQueue = new MessageQueue(); OffsetWrapper offsetWrapper = new OffsetWrapper(); HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>(); stats.put(messageQueue, offsetWrapper); consumeStats.setOffsetTable(stats); when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats); ConsumerConnection consumerConnection = new ConsumerConnection(); consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY); consumerConnection.setMessageModel(MessageModel.CLUSTERING); HashSet<Connection> connections = new HashSet<>(); Connection connection = new Connection(); connection.setClientId("client_id"); connection.setClientAddr("127.0.0.1:109111"); connection.setLanguage(LanguageCode.JAVA); connection.setVersion(MQVersion.Version.V4_0_0_SNAPSHOT.ordinal()); connections.add(connection); consumerConnection.setConnectionSet(connections); consumerConnection.setSubscriptionTable(new ConcurrentHashMap<String, SubscriptionData>()); consumerConnection.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); when(mQClientAPIImpl.getConsumerConnectionList(anyString(), anyString(), anyLong())).thenReturn(consumerConnection); ConsumerRunningInfo consumerRunningInfo = new ConsumerRunningInfo(); consumerRunningInfo.setJstack("test"); consumerRunningInfo.setMqTable(new TreeMap<MessageQueue, ProcessQueueInfo>()); consumerRunningInfo.setStatusTable(new TreeMap<String, ConsumeStatus>()); consumerRunningInfo.setSubscriptionSet(new TreeSet<SubscriptionData>()); Properties properties = new Properties(); properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, CONSUME_ACTIVELY); properties.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, System.currentTimeMillis()); consumerRunningInfo.setProperties(properties); when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo); }