Search in sources :

Example 6 with SubscriptionGroupConfig

use of org.apache.rocketmq.common.subscription.SubscriptionGroupConfig in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class SubscriptionGroupManager method disableConsume.

/**
 * 不能消费,设置消费标记为false
 * @param groupName
 */
public void disableConsume(final String groupName) {
    SubscriptionGroupConfig old = this.subscriptionGroupTable.get(groupName);
    if (old != null) {
        old.setConsumeEnable(false);
        this.dataVersion.nextVersion();
    }
}
Also used : SubscriptionGroupConfig(org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)

Example 7 with SubscriptionGroupConfig

use of org.apache.rocketmq.common.subscription.SubscriptionGroupConfig in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class SubscriptionGroupManager method findSubscriptionGroupConfig.

public SubscriptionGroupConfig findSubscriptionGroupConfig(final String group) {
    SubscriptionGroupConfig subscriptionGroupConfig = this.subscriptionGroupTable.get(group);
    if (null == subscriptionGroupConfig) {
        if (brokerController.getBrokerConfig().isAutoCreateSubscriptionGroup() || MixAll.isSysConsumerGroup(group)) {
            subscriptionGroupConfig = new SubscriptionGroupConfig();
            subscriptionGroupConfig.setGroupName(group);
            SubscriptionGroupConfig preConfig = this.subscriptionGroupTable.putIfAbsent(group, subscriptionGroupConfig);
            if (null == preConfig) {
                log.info("auto create a subscription group, {}", subscriptionGroupConfig.toString());
            }
            this.dataVersion.nextVersion();
            this.persist();
        }
    }
    return subscriptionGroupConfig;
}
Also used : SubscriptionGroupConfig(org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)

Example 8 with SubscriptionGroupConfig

use of org.apache.rocketmq.common.subscription.SubscriptionGroupConfig in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class SubscriptionGroupManager method deleteSubscriptionGroupConfig.

public void deleteSubscriptionGroupConfig(final String groupName) {
    SubscriptionGroupConfig old = this.subscriptionGroupTable.remove(groupName);
    if (old != null) {
        log.info("delete subscription group OK, subscription group:{}", old);
        this.dataVersion.nextVersion();
        this.persist();
    } else {
        log.warn("delete subscription group failed, subscription groupName: {} not exist", groupName);
    }
}
Also used : SubscriptionGroupConfig(org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)

Example 9 with SubscriptionGroupConfig

use of org.apache.rocketmq.common.subscription.SubscriptionGroupConfig in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MQAdmin method getSubConnection.

public void getSubConnection(String nameSrvAddr, String clusterName, String consumerId) {
    boolean createResult = true;
    DefaultMQAdminExt mqAdminExt = new DefaultMQAdminExt();
    mqAdminExt.setNamesrvAddr(nameSrvAddr);
    SubscriptionGroupConfig config = new SubscriptionGroupConfig();
    config.setGroupName(consumerId);
    try {
        mqAdminExt.start();
        Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(mqAdminExt, clusterName);
        for (String addr : masterSet) {
            try {
                System.out.printf("create subscription group %s to %s success.\n", consumerId, addr);
            } catch (Exception e) {
                e.printStackTrace();
                Thread.sleep(1000 * 1);
            }
        }
    } catch (Exception e) {
        createResult = false;
        e.printStackTrace();
    }
    mqAdminExt.shutdown();
}
Also used : DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) SubscriptionGroupConfig(org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)

Example 10 with SubscriptionGroupConfig

use of org.apache.rocketmq.common.subscription.SubscriptionGroupConfig in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MQAdmin method createSub.

public static boolean createSub(String nameSrvAddr, String clusterName, String consumerId) {
    boolean createResult = true;
    DefaultMQAdminExt mqAdminExt = new DefaultMQAdminExt();
    mqAdminExt.setNamesrvAddr(nameSrvAddr);
    SubscriptionGroupConfig config = new SubscriptionGroupConfig();
    config.setGroupName(consumerId);
    try {
        mqAdminExt.start();
        Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(mqAdminExt, clusterName);
        for (String addr : masterSet) {
            try {
                mqAdminExt.createAndUpdateSubscriptionGroupConfig(addr, config);
                log.info(String.format("create subscription group %s to %s success.\n", consumerId, addr));
            } catch (Exception e) {
                e.printStackTrace();
                Thread.sleep(1000 * 1);
            }
        }
    } catch (Exception e) {
        createResult = false;
        e.printStackTrace();
    }
    mqAdminExt.shutdown();
    return createResult;
}
Also used : DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) SubscriptionGroupConfig(org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)

Aggregations

SubscriptionGroupConfig (org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)34 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)12 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)7 TopicConfig (org.apache.rocketmq.common.TopicConfig)6 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)6 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Set (java.util.Set)4 ClientChannelInfo (org.apache.rocketmq.broker.client.ClientChannelInfo)4 ConsumeMessageContext (org.apache.rocketmq.broker.mqtrace.ConsumeMessageContext)4 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)4 OffsetWrapper (org.apache.rocketmq.common.admin.OffsetWrapper)4 MQClientException (org.apache.rocketmq.client.exception.MQClientException)3 MessageExt (org.apache.rocketmq.common.message.MessageExt)3 ConsumeStatsList (org.apache.rocketmq.common.protocol.body.ConsumeStatsList)3 GroupList (org.apache.rocketmq.common.protocol.body.GroupList)3 TopicList (org.apache.rocketmq.common.protocol.body.TopicList)3