Java Code Examples for org.apache.rocketmq.broker.client.ClientChannelInfo#getClientId()

The following examples show how to use org.apache.rocketmq.broker.client.ClientChannelInfo#getClientId() . 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: DeFiPullMessageProcessor.java    From DeFiBus with Apache License 2.0 6 votes vote down vote up
@Override
public RemotingCommand processRequest(final ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    RemotingCommand response = super.processRequest(ctx, request);

    final PullMessageRequestHeader requestHeader =
        (PullMessageRequestHeader) request.decodeCommandCustomHeader(PullMessageRequestHeader.class);
    ConsumerGroupInfo consumerGroupInfo = deFiBrokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup());
    if (consumerGroupInfo != null) {
        ClientChannelInfo clientChannelInfo = consumerGroupInfo.getChannelInfoTable().get(ctx.channel());
        if (clientChannelInfo != null) {
            String clientId = clientChannelInfo.getClientId();
            deFiBrokerController.getClientRebalanceResultManager().updateListenMap(requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueId(), clientId);
        }
    }
    handleProcessResult(requestHeader, response);
    return response;
}
 
Example 2
Source File: DeFiConsumerGroupInfo.java    From DeFiBus with Apache License 2.0 6 votes vote down vote up
public Set<String> unregisterClientId(final ClientChannelInfo clientChannelInfo) {
    Set<String> whichTopic = new HashSet<>();
    if (clientChannelInfo != null) {
        String clientId = clientChannelInfo.getClientId();
        Iterator<Map.Entry<String, CopyOnWriteArraySet<String>>> it = clientIdMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, CopyOnWriteArraySet<String>> entry = it.next();
            if (entry.getValue().contains(clientId)) {
                log.info("unregister clientId {} from {}", clientId, entry.getKey());
                entry.getValue().remove(clientId);
                whichTopic.add(entry.getKey());
                if (entry.getValue().isEmpty()) {
                    log.info("unregister clientId, clientId set of {} is empty, remove it.", entry.getKey());
                    it.remove();
                }
            }
        }
    }
    return whichTopic;
}