Search in sources :

Example 6 with ConsumerData

use of org.apache.rocketmq.common.protocol.heartbeat.ConsumerData 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)

Example 7 with ConsumerData

use of org.apache.rocketmq.common.protocol.heartbeat.ConsumerData in project rocketmq by apache.

the class MQClientInstance method prepareHeartbeatData.

private HeartbeatData prepareHeartbeatData() {
    HeartbeatData heartbeatData = new HeartbeatData();
    // clientID
    heartbeatData.setClientID(this.clientId);
    // Consumer
    for (Map.Entry<String, MQConsumerInner> entry : this.consumerTable.entrySet()) {
        MQConsumerInner impl = entry.getValue();
        if (impl != null) {
            ConsumerData consumerData = new ConsumerData();
            consumerData.setGroupName(impl.groupName());
            consumerData.setConsumeType(impl.consumeType());
            consumerData.setMessageModel(impl.messageModel());
            consumerData.setConsumeFromWhere(impl.consumeFromWhere());
            consumerData.getSubscriptionDataSet().addAll(impl.subscriptions());
            consumerData.setUnitMode(impl.isUnitMode());
            heartbeatData.getConsumerDataSet().add(consumerData);
        }
    }
    // Producer
    for (Map.Entry<String, MQProducerInner> /* group */
    entry : this.producerTable.entrySet()) {
        MQProducerInner impl = entry.getValue();
        if (impl != null) {
            ProducerData producerData = new ProducerData();
            producerData.setGroupName(entry.getKey());
            heartbeatData.getProducerDataSet().add(producerData);
        }
    }
    return heartbeatData;
}
Also used : MQConsumerInner(org.apache.rocketmq.client.impl.consumer.MQConsumerInner) MQProducerInner(org.apache.rocketmq.client.impl.producer.MQProducerInner) ConsumerData(org.apache.rocketmq.common.protocol.heartbeat.ConsumerData) HeartbeatData(org.apache.rocketmq.common.protocol.heartbeat.HeartbeatData) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ProducerData(org.apache.rocketmq.common.protocol.heartbeat.ProducerData)

Example 8 with ConsumerData

use of org.apache.rocketmq.common.protocol.heartbeat.ConsumerData in project rocketmq by apache.

the class ClientManageProcessor method heartBeat.

public RemotingCommand heartBeat(ChannelHandlerContext ctx, RemotingCommand request) {
    RemotingCommand response = RemotingCommand.createResponseCommand(null);
    HeartbeatData heartbeatData = HeartbeatData.decode(request.getBody(), HeartbeatData.class);
    ClientChannelInfo clientChannelInfo = new ClientChannelInfo(ctx.channel(), heartbeatData.getClientID(), request.getLanguage(), request.getVersion());
    for (ConsumerData data : heartbeatData.getConsumerDataSet()) {
        SubscriptionGroupConfig subscriptionGroupConfig = this.brokerController.getSubscriptionGroupManager().findSubscriptionGroupConfig(data.getGroupName());
        boolean isNotifyConsumerIdsChangedEnable = true;
        if (null != subscriptionGroupConfig) {
            isNotifyConsumerIdsChangedEnable = subscriptionGroupConfig.isNotifyConsumerIdsChangedEnable();
            int topicSysFlag = 0;
            if (data.isUnitMode()) {
                topicSysFlag = TopicSysFlag.buildSysFlag(false, true);
            }
            String newTopic = MixAll.getRetryTopic(data.getGroupName());
            this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(newTopic, subscriptionGroupConfig.getRetryQueueNums(), PermName.PERM_WRITE | PermName.PERM_READ, topicSysFlag);
        }
        boolean changed = this.brokerController.getConsumerManager().registerConsumer(data.getGroupName(), clientChannelInfo, data.getConsumeType(), data.getMessageModel(), data.getConsumeFromWhere(), data.getSubscriptionDataSet(), isNotifyConsumerIdsChangedEnable);
        if (changed) {
            log.info("registerConsumer info changed {} {}", data.toString(), RemotingHelper.parseChannelRemoteAddr(ctx.channel()));
        }
    }
    for (ProducerData data : heartbeatData.getProducerDataSet()) {
        this.brokerController.getProducerManager().registerProducer(data.getGroupName(), clientChannelInfo);
    }
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ClientChannelInfo(org.apache.rocketmq.broker.client.ClientChannelInfo) ConsumerData(org.apache.rocketmq.common.protocol.heartbeat.ConsumerData) HeartbeatData(org.apache.rocketmq.common.protocol.heartbeat.HeartbeatData) ProducerData(org.apache.rocketmq.common.protocol.heartbeat.ProducerData) SubscriptionGroupConfig(org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)

Example 9 with ConsumerData

use of org.apache.rocketmq.common.protocol.heartbeat.ConsumerData in project rocketmq by apache.

the class PullMessageProcessorTest method createConsumerData.

static ConsumerData createConsumerData(String group, String topic) {
    ConsumerData consumerData = new ConsumerData();
    consumerData.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    consumerData.setConsumeType(ConsumeType.CONSUME_PASSIVELY);
    consumerData.setGroupName(group);
    consumerData.setMessageModel(MessageModel.CLUSTERING);
    Set<SubscriptionData> subscriptionDataSet = new HashSet<>();
    SubscriptionData subscriptionData = new SubscriptionData();
    subscriptionData.setTopic(topic);
    subscriptionData.setSubString("*");
    subscriptionData.setSubVersion(100L);
    subscriptionDataSet.add(subscriptionData);
    consumerData.setSubscriptionDataSet(subscriptionDataSet);
    return consumerData;
}
Also used : ConsumerData(org.apache.rocketmq.common.protocol.heartbeat.ConsumerData) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) HashSet(java.util.HashSet)

Example 10 with ConsumerData

use of org.apache.rocketmq.common.protocol.heartbeat.ConsumerData in project rocketmq by apache.

the class PullMessageProcessorTest method init.

@Before
public void init() {
    brokerController.setMessageStore(messageStore);
    pullMessageProcessor = new PullMessageProcessor(brokerController);
    Channel mockChannel = mock(Channel.class);
    when(mockChannel.remoteAddress()).thenReturn(new InetSocketAddress(1024));
    when(handlerContext.channel()).thenReturn(mockChannel);
    brokerController.getTopicConfigManager().getTopicConfigTable().put(topic, new TopicConfig());
    clientChannelInfo = new ClientChannelInfo(mockChannel);
    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) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) TopicConfig(org.apache.rocketmq.common.TopicConfig) Before(org.junit.Before)

Aggregations

ConsumerData (org.apache.rocketmq.common.protocol.heartbeat.ConsumerData)10 ClientChannelInfo (org.apache.rocketmq.broker.client.ClientChannelInfo)6 HeartbeatData (org.apache.rocketmq.common.protocol.heartbeat.HeartbeatData)4 ProducerData (org.apache.rocketmq.common.protocol.heartbeat.ProducerData)4 Before (org.junit.Before)4 Channel (io.netty.channel.Channel)2 InetSocketAddress (java.net.InetSocketAddress)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 PullMessageProcessorTest.createConsumerData (org.apache.rocketmq.broker.processor.PullMessageProcessorTest.createConsumerData)2 MQConsumerInner (org.apache.rocketmq.client.impl.consumer.MQConsumerInner)2 MQProducerInner (org.apache.rocketmq.client.impl.producer.MQProducerInner)2 TopicConfig (org.apache.rocketmq.common.TopicConfig)2 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)2 SubscriptionGroupConfig (org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)2 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)2