Search in sources :

Example 11 with ClientChannelInfo

use of org.apache.rocketmq.broker.client.ClientChannelInfo in project rocketmq by apache.

the class AdminBrokerProcessor method getProducerConnectionList.

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;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ClientChannelInfo(org.apache.rocketmq.broker.client.ClientChannelInfo) GetProducerConnectionListRequestHeader(org.apache.rocketmq.common.protocol.header.GetProducerConnectionListRequestHeader) Channel(io.netty.channel.Channel) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) Connection(org.apache.rocketmq.common.protocol.body.Connection) ProducerConnection(org.apache.rocketmq.common.protocol.body.ProducerConnection) ProducerConnection(org.apache.rocketmq.common.protocol.body.ProducerConnection)

Example 12 with ClientChannelInfo

use of org.apache.rocketmq.broker.client.ClientChannelInfo in project rocketmq by apache.

the class AdminBrokerProcessor method getConsumerConnectionList.

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;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetConsumerConnectionListRequestHeader(org.apache.rocketmq.common.protocol.header.GetConsumerConnectionListRequestHeader) ClientChannelInfo(org.apache.rocketmq.broker.client.ClientChannelInfo) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) Connection(org.apache.rocketmq.common.protocol.body.Connection) ProducerConnection(org.apache.rocketmq.common.protocol.body.ProducerConnection) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) ConsumerGroupInfo(org.apache.rocketmq.broker.client.ConsumerGroupInfo)

Example 13 with ClientChannelInfo

use of org.apache.rocketmq.broker.client.ClientChannelInfo in project rocketmq by apache.

the class ClientManageProcessor method unregisterClient.

public RemotingCommand unregisterClient(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(UnregisterClientResponseHeader.class);
    final UnregisterClientRequestHeader requestHeader = (UnregisterClientRequestHeader) request.decodeCommandCustomHeader(UnregisterClientRequestHeader.class);
    ClientChannelInfo clientChannelInfo = new ClientChannelInfo(ctx.channel(), requestHeader.getClientID(), request.getLanguage(), request.getVersion());
    {
        final String group = requestHeader.getProducerGroup();
        if (group != null) {
            this.brokerController.getProducerManager().unregisterProducer(group, clientChannelInfo);
        }
    }
    {
        final String group = requestHeader.getConsumerGroup();
        if (group != null) {
            SubscriptionGroupConfig subscriptionGroupConfig = this.brokerController.getSubscriptionGroupManager().findSubscriptionGroupConfig(group);
            boolean isNotifyConsumerIdsChangedEnable = true;
            if (null != subscriptionGroupConfig) {
                isNotifyConsumerIdsChangedEnable = subscriptionGroupConfig.isNotifyConsumerIdsChangedEnable();
            }
            this.brokerController.getConsumerManager().unregisterConsumer(group, clientChannelInfo, isNotifyConsumerIdsChangedEnable);
        }
    }
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) UnregisterClientRequestHeader(org.apache.rocketmq.common.protocol.header.UnregisterClientRequestHeader) ClientChannelInfo(org.apache.rocketmq.broker.client.ClientChannelInfo) SubscriptionGroupConfig(org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)

Example 14 with ClientChannelInfo

use of org.apache.rocketmq.broker.client.ClientChannelInfo in project rocketmq by apache.

the class ClientManageProcessorTest method processRequest_UnRegisterProducer.

@Test
public void processRequest_UnRegisterProducer() throws Exception {
    brokerController.getProducerManager().registerProducer(group, clientChannelInfo);
    HashMap<Channel, ClientChannelInfo> channelMap = brokerController.getProducerManager().getGroupChannelTable().get(group);
    assertThat(channelMap).isNotNull();
    assertThat(channelMap.get(channel)).isEqualTo(clientChannelInfo);
    RemotingCommand request = createUnRegisterProducerCommand();
    RemotingCommand response = clientManageProcessor.processRequest(handlerContext, request);
    assertThat(response).isNotNull();
    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
    channelMap = brokerController.getProducerManager().getGroupChannelTable().get(group);
    assertThat(channelMap).isNull();
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ClientChannelInfo(org.apache.rocketmq.broker.client.ClientChannelInfo) Channel(io.netty.channel.Channel) Test(org.junit.Test)

Example 15 with ClientChannelInfo

use of org.apache.rocketmq.broker.client.ClientChannelInfo in project rocketmq by apache.

the class ClientManageProcessorTest method init.

@Before
public void init() {
    when(handlerContext.channel()).thenReturn(channel);
    clientManageProcessor = new ClientManageProcessor(brokerController);
    clientChannelInfo = new ClientChannelInfo(channel, clientId, LanguageCode.JAVA, 100);
    brokerController.getProducerManager().registerProducer(group, clientChannelInfo);
    ConsumerData consumerData = createConsumerData(group, topic);
    brokerController.getConsumerManager().registerConsumer(consumerData.getGroupName(), clientChannelInfo, consumerData.getConsumeType(), consumerData.getMessageModel(), consumerData.getConsumeFromWhere(), consumerData.getSubscriptionDataSet(), false);
}
Also used : ClientChannelInfo(org.apache.rocketmq.broker.client.ClientChannelInfo) ConsumerData(org.apache.rocketmq.common.protocol.heartbeat.ConsumerData) PullMessageProcessorTest.createConsumerData(org.apache.rocketmq.broker.processor.PullMessageProcessorTest.createConsumerData) Before(org.junit.Before)

Aggregations

ClientChannelInfo (org.apache.rocketmq.broker.client.ClientChannelInfo)20 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)16 Channel (io.netty.channel.Channel)10 ConsumerData (org.apache.rocketmq.common.protocol.heartbeat.ConsumerData)6 RemotingTimeoutException (org.apache.rocketmq.remoting.exception.RemotingTimeoutException)6 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 ConsumerGroupInfo (org.apache.rocketmq.broker.client.ConsumerGroupInfo)4 TopicConfig (org.apache.rocketmq.common.TopicConfig)4 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)4 Connection (org.apache.rocketmq.common.protocol.body.Connection)4 ConsumerConnection (org.apache.rocketmq.common.protocol.body.ConsumerConnection)4 ProducerConnection (org.apache.rocketmq.common.protocol.body.ProducerConnection)4 SubscriptionGroupConfig (org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)4 RemotingSendRequestException (org.apache.rocketmq.remoting.exception.RemotingSendRequestException)4 Before (org.junit.Before)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InetSocketAddress (java.net.InetSocketAddress)2 UnknownHostException (java.net.UnknownHostException)2