Search in sources :

Example 11 with SubscriptionData

use of org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class FilterAPITest method testBuildSQL.

@Test
public void testBuildSQL() {
    try {
        SubscriptionData subscriptionData = FilterAPI.build("TOPIC", "a is not null", ExpressionType.SQL92);
        assertThat(subscriptionData).isNotNull();
        assertThat(subscriptionData.getTopic()).isEqualTo("TOPIC");
        assertThat(subscriptionData.getExpressionType()).isEqualTo(ExpressionType.SQL92);
    } catch (Exception e) {
        e.printStackTrace();
        assertThat(Boolean.FALSE).isTrue();
    }
}
Also used : SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) Test(org.junit.Test)

Example 12 with SubscriptionData

use of org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class FilterAPITest method testBuildTagSome.

@Test
public void testBuildTagSome() {
    try {
        SubscriptionData subscriptionData = FilterAPI.build("TOPIC", "A || B", ExpressionType.TAG);
        assertThat(subscriptionData).isNotNull();
        assertThat(subscriptionData.getTopic()).isEqualTo("TOPIC");
        assertThat(subscriptionData.getSubString()).isEqualTo("A || B");
        assertThat(ExpressionType.isTagType(subscriptionData.getExpressionType())).isTrue();
        assertThat(subscriptionData.getTagsSet()).isNotNull();
        assertThat(subscriptionData.getTagsSet()).containsExactly("A", "B");
    } catch (Exception e) {
        e.printStackTrace();
        assertThat(Boolean.FALSE).isTrue();
    }
}
Also used : SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) Test(org.junit.Test)

Example 13 with SubscriptionData

use of org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQPushConsumerImpl method subscribe.

public void subscribe(String topic, String fullClassName, String filterClassSource) throws MQClientException {
    try {
        SubscriptionData subscriptionData = // 
        FilterAPI.buildSubscriptionData(// 
        this.defaultMQPushConsumer.getConsumerGroup(), topic, "*");
        subscriptionData.setSubString(fullClassName);
        subscriptionData.setClassFilterMode(true);
        subscriptionData.setFilterClassSource(filterClassSource);
        this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
        if (this.mQClientFactory != null) {
            this.mQClientFactory.sendHeartbeatToAllBrokerWithLock();
        }
    } catch (Exception e) {
        throw new MQClientException("subscription exception", e);
    }
}
Also used : SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) MQClientException(org.apache.rocketmq.client.exception.MQClientException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 14 with SubscriptionData

use of org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQPullConsumerImpl method copySubscription.

private void copySubscription() throws MQClientException {
    try {
        Set<String> registerTopics = this.defaultMQPullConsumer.getRegisterTopics();
        if (registerTopics != null) {
            for (final String topic : registerTopics) {
                SubscriptionData subscriptionData = // 
                FilterAPI.buildSubscriptionData(// 
                this.defaultMQPullConsumer.getConsumerGroup(), topic, SubscriptionData.SUB_ALL);
                this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
            }
        }
    } catch (Exception e) {
        throw new MQClientException("subscription exception", e);
    }
}
Also used : SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 15 with SubscriptionData

use of org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQPushConsumerImpl method consumerRunningInfo.

@Override
public ConsumerRunningInfo consumerRunningInfo() {
    ConsumerRunningInfo info = new ConsumerRunningInfo();
    Properties prop = MixAll.object2Properties(this.defaultMQPushConsumer);
    prop.put(ConsumerRunningInfo.PROP_CONSUME_ORDERLY, String.valueOf(this.consumeOrderly));
    prop.put(ConsumerRunningInfo.PROP_THREADPOOL_CORE_SIZE, String.valueOf(this.consumeMessageService.getCorePoolSize()));
    prop.put(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP, String.valueOf(this.consumerStartTimestamp));
    info.setProperties(prop);
    Set<SubscriptionData> subSet = this.subscriptions();
    info.getSubscriptionSet().addAll(subSet);
    Iterator<Entry<MessageQueue, ProcessQueue>> it = this.rebalanceImpl.getProcessQueueTable().entrySet().iterator();
    while (it.hasNext()) {
        Entry<MessageQueue, ProcessQueue> next = it.next();
        MessageQueue mq = next.getKey();
        ProcessQueue pq = next.getValue();
        ProcessQueueInfo pqinfo = new ProcessQueueInfo();
        pqinfo.setCommitOffset(this.offsetStore.readOffset(mq, ReadOffsetType.MEMORY_FIRST_THEN_STORE));
        pq.fillProcessQueueInfo(pqinfo);
        info.getMqTable().put(mq, pqinfo);
    }
    for (SubscriptionData sd : subSet) {
        ConsumeStatus consumeStatus = this.mQClientFactory.getConsumerStatsManager().consumeStatus(this.groupName(), sd.getTopic());
        info.getStatusTable().put(sd.getTopic(), consumeStatus);
    }
    return info;
}
Also used : ProcessQueueInfo(org.apache.rocketmq.common.protocol.body.ProcessQueueInfo) Entry(java.util.Map.Entry) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) ConsumerRunningInfo(org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo) Properties(java.util.Properties) ConsumeStatus(org.apache.rocketmq.common.protocol.body.ConsumeStatus)

Aggregations

SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)77 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)24 MQClientException (org.apache.rocketmq.client.exception.MQClientException)24 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)24 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)18 HashSet (java.util.HashSet)16 ArrayList (java.util.ArrayList)14 List (java.util.List)12 Entry (java.util.Map.Entry)12 ConsumerConnection (org.apache.rocketmq.common.protocol.body.ConsumerConnection)12 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)12 HashMap (java.util.HashMap)10 Connection (org.apache.rocketmq.common.protocol.body.Connection)10 ConsumeStatus (org.apache.rocketmq.common.protocol.body.ConsumeStatus)10 ConsumerRunningInfo (org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo)10 ProcessQueueInfo (org.apache.rocketmq.common.protocol.body.ProcessQueueInfo)10 Test (org.junit.Test)9 Field (java.lang.reflect.Field)8 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)8 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)8