当前位置: 首页>>代码示例>>Java>>正文


Java DefaultMQPushConsumer.setConsumeMessageBatchMaxSize方法代码示例

本文整理汇总了Java中org.apache.rocketmq.client.consumer.DefaultMQPushConsumer.setConsumeMessageBatchMaxSize方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMQPushConsumer.setConsumeMessageBatchMaxSize方法的具体用法?Java DefaultMQPushConsumer.setConsumeMessageBatchMaxSize怎么用?Java DefaultMQPushConsumer.setConsumeMessageBatchMaxSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.rocketmq.client.consumer.DefaultMQPushConsumer的用法示例。


在下文中一共展示了DefaultMQPushConsumer.setConsumeMessageBatchMaxSize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pushConsumer

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
@Bean
public DefaultMQPushConsumer pushConsumer() throws MQClientException {
    /**
     * 一个应用创建一个Consumer,由应用来维护此对象,可以设置为全局对象或者单例<br>
     * 注意:ConsumerGroupName需要由应用来保证唯一
     */
    DefaultMQPushConsumer consumer =
            new DefaultMQPushConsumer(env.getProperty("spring.rocketmq.consumerGroupName"));
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    consumer.setNamesrvAddr(env.getProperty("spring.rocketmq.namesrvAddr"));
    consumer.setInstanceName(env.getProperty("spring.rocketmq.instanceName"));
    //设置批量消费,以提升消费吞吐量,默认是1
    consumer.setConsumeMessageBatchMaxSize(1);

    /**
     * 订阅指定topic下tags
     */
    consumer.subscribe(TOPIC, TOPIC);

    consumer.registerMessageListener((List<MessageExt> msgList, ConsumeConcurrentlyContext context) -> {

        MessageExt msg = msgList.get(0);
        try {
            // 默认msgList里只有一条消息,可以通过设置consumeMessageBatchMaxSize参数来批量接收消息
            final byte[] message = msg.getBody();
            final Boolean success = mythMqReceiveService.processMessage(message);
            if(success){
                //如果没有return success,consumer会重复消费此信息,直到success。
                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
            }

        } catch (Exception e) {
            e.printStackTrace();
            //重复消费3次
            return ConsumeConcurrentlyStatus.RECONSUME_LATER;
        }
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;

    });

    consumer.start();

    return consumer;
}
 
开发者ID:yu199195,项目名称:myth,代码行数:45,代码来源:RocketmqConsumer.java

示例2: pushConsumer

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
@Bean
public DefaultMQPushConsumer pushConsumer() throws MQClientException {
    /**
     * 一个应用创建一个Consumer,由应用来维护此对象,可以设置为全局对象或者单例<br>
     * 注意:ConsumerGroupName需要由应用来保证唯一
     */
    DefaultMQPushConsumer consumer =
            new DefaultMQPushConsumer(env.getProperty("spring.rocketmq.consumerGroupName"));
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    consumer.setNamesrvAddr(env.getProperty("spring.rocketmq.namesrvAddr"));
    consumer.setInstanceName(env.getProperty("spring.rocketmq.instanceName"));
    //设置批量消费,以提升消费吞吐量,默认是1
    consumer.setConsumeMessageBatchMaxSize(1);


    /**
     * 订阅指定topic下tags
     */
    consumer.subscribe(QUEUE, QUEUE);

    consumer.registerMessageListener((List<MessageExt> msgList,
                                      ConsumeConcurrentlyContext context) -> {

        MessageExt msg = msgList.get(0);
        try {
            // 默认msgList里只有一条消息,可以通过设置consumeMessageBatchMaxSize参数来批量接收消息
            final byte[] message = msg.getBody();
            final Boolean success = mythMqReceiveService.processMessage(message);
            if(success){
                LogUtil.debug(LOGGER,()->"motan 框架消费rocketmq消息成功");
            }

        } catch (Exception e) {
            e.printStackTrace();
            //重复消费3次
            return ConsumeConcurrentlyStatus.RECONSUME_LATER;
        }

        //如果没有return success,consumer会重复消费此信息,直到success。
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    });

    /**
     * Consumer对象在使用之前必须要调用start初始化,初始化一次即可<br>
     */
    consumer.start();

    return consumer;
}
 
开发者ID:yu199195,项目名称:myth,代码行数:50,代码来源:RocketmqConsumer.java

示例3: pushConsumer

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
@Bean
public DefaultMQPushConsumer pushConsumer() throws MQClientException {
    /**
     * 一个应用创建一个Consumer,由应用来维护此对象,可以设置为全局对象或者单例<br>
     * 注意:ConsumerGroupName需要由应用来保证唯一
     */
    DefaultMQPushConsumer consumer =
            new DefaultMQPushConsumer(env.getProperty("spring.rocketmq.consumerGroupName"));
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    consumer.setNamesrvAddr(env.getProperty("spring.rocketmq.namesrvAddr"));
    consumer.setInstanceName(env.getProperty("spring.rocketmq.instanceName"));
    //设置批量消费,以提升消费吞吐量,默认是1
    consumer.setConsumeMessageBatchMaxSize(1);
    //RECONSUME_LATER的重试次数,RocketMQ默认是16次
    consumer.setMaxReconsumeTimes(mythConfig.getRetryMax());

    /**
     * 订阅指定topic下tags
     */
    consumer.subscribe(TOPIC, TOPIC);

    consumer.registerMessageListener((List<MessageExt> msgList, ConsumeConcurrentlyContext context) -> {

        MessageExt msg = msgList.get(0);
        try {
            // 默认msgList里只有一条消息,可以通过设置consumeMessageBatchMaxSize参数来批量接收消息
            final byte[] message = msg.getBody();
            mythMqReceiveService.processMessage(message);

        } catch (Exception e) {
            e.printStackTrace();
            //重复消费3次
            return ConsumeConcurrentlyStatus.RECONSUME_LATER;
        }

        //如果没有return success,consumer会重复消费此信息,直到success。
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    });

    /**
     * Consumer对象在使用之前必须要调用start初始化,初始化一次即可<br>
     */
    consumer.start();

    return consumer;
}
 
开发者ID:yu199195,项目名称:myth,代码行数:47,代码来源:RocketmqConsumer.java

示例4: pushConsumer

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
@Bean
public DefaultMQPushConsumer pushConsumer() throws MQClientException {
    /**
     * 一个应用创建一个Consumer,由应用来维护此对象,可以设置为全局对象或者单例<br>
     * 注意:ConsumerGroupName需要由应用来保证唯一
     */
    DefaultMQPushConsumer consumer =
            new DefaultMQPushConsumer(env.getProperty("spring.rocketmq.consumerGroupName"));
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    consumer.setNamesrvAddr(env.getProperty("spring.rocketmq.namesrvAddr"));
    consumer.setInstanceName(env.getProperty("spring.rocketmq.instanceName"));
    //设置批量消费,以提升消费吞吐量,默认是1
    consumer.setConsumeMessageBatchMaxSize(2);
    //RECONSUME_LATER的重试次数,RocketMQ默认是16次
    consumer.setMaxReconsumeTimes(mythConfig.getRetryMax());

    /**
     * 订阅指定topic下tags
     */
    consumer.subscribe(QUEUE, QUEUE);

    consumer.registerMessageListener((List<MessageExt> msgList,
                                      ConsumeConcurrentlyContext context) -> {

        MessageExt msg = msgList.get(0);
        try {
            // 默认msgList里只有一条消息,可以通过设置consumeMessageBatchMaxSize参数来批量接收消息
            final byte[] message = msg.getBody();
            final Boolean aBoolean = mythMqReceiveService.processMessage(message);

        } catch (Exception e) {
            e.printStackTrace();
            //重复消费
            return ConsumeConcurrentlyStatus.RECONSUME_LATER;
        }

        //如果没有return success,consumer会重复消费此信息,直到success。
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    });

    /**
     * Consumer对象在使用之前必须要调用start初始化,初始化一次即可<br>
     */
    consumer.start();

    return consumer;
}
 
开发者ID:yu199195,项目名称:myth,代码行数:48,代码来源:RocketmqConsumer.java

示例5: pushConsumer

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
@Bean
public DefaultMQPushConsumer pushConsumer() throws MQClientException {
    /**
     * 一个应用创建一个Consumer,由应用来维护此对象,可以设置为全局对象或者单例<br>
     * 注意:ConsumerGroupName需要由应用来保证唯一
     */
    DefaultMQPushConsumer consumer =
            new DefaultMQPushConsumer(env.getProperty("spring.rocketmq.consumerGroupName"));
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    consumer.setNamesrvAddr(env.getProperty("spring.rocketmq.namesrvAddr"));
    consumer.setInstanceName(env.getProperty("spring.rocketmq.instanceName"));
    //设置批量消费,以提升消费吞吐量,默认是1
    consumer.setConsumeMessageBatchMaxSize(1);

    /**
     * 订阅指定topic下tags
     */
    consumer.subscribe(TOPIC, TOPIC);

    consumer.registerMessageListener((List<MessageExt> msgList, ConsumeConcurrentlyContext context) -> {

        MessageExt msg = msgList.get(0);
        try {
            // 默认msgList里只有一条消息,可以通过设置consumeMessageBatchMaxSize参数来批量接收消息
            final byte[] message = msg.getBody();
            LogUtil.debug(LOGGER, () -> "springcloud account-service rocketmq 接收到myth框架发出的信息====");
            final Boolean success = mythMqReceiveService.processMessage(message);
            if (success) {
                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
            }

        } catch (Exception e) {
            e.printStackTrace();
            //重复消费
            return ConsumeConcurrentlyStatus.RECONSUME_LATER;
        }

        //如果没有return success,consumer会重复消费此信息,直到success。
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    });

    /**
     * Consumer对象在使用之前必须要调用start初始化,初始化一次即可<br>
     */
    consumer.start();

    return consumer;
}
 
开发者ID:yu199195,项目名称:myth,代码行数:49,代码来源:RocketmqConsumer.java

示例6: pushConsumer

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
@Bean
public DefaultMQPushConsumer pushConsumer() throws MQClientException {
    /**
     * 一个应用创建一个Consumer,由应用来维护此对象,可以设置为全局对象或者单例<br>
     * 注意:ConsumerGroupName需要由应用来保证唯一
     */
    DefaultMQPushConsumer consumer =
            new DefaultMQPushConsumer(env.getProperty("spring.rocketmq.consumerGroupName"));
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    consumer.setNamesrvAddr(env.getProperty("spring.rocketmq.namesrvAddr"));
    consumer.setInstanceName(env.getProperty("spring.rocketmq.instanceName"));
    //设置批量消费,以提升消费吞吐量,默认是1
    consumer.setConsumeMessageBatchMaxSize(3);


    consumer.subscribe(QUEUE, QUEUE);

    consumer.registerMessageListener((List<MessageExt> msgList,
                                      ConsumeConcurrentlyContext context) -> {

        MessageExt msg = msgList.get(0);
        try {
            // 默认msgList里只有一条消息,可以通过设置consumeMessageBatchMaxSize参数来批量接收消息
            final byte[] message = msg.getBody();
            LogUtil.debug(LOGGER,()->"springcloud inventory-serivce rocketmq 接收到myth框架发出的信息====");

            final Boolean success = mythMqReceiveService.processMessage(message);


        } catch (Exception e) {
            e.printStackTrace();
            return ConsumeConcurrentlyStatus.RECONSUME_LATER;
        }

        //如果没有return success,consumer会重复消费此信息,直到success。
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    });

    consumer.start();

    return consumer;
}
 
开发者ID:yu199195,项目名称:myth,代码行数:43,代码来源:RocketmqConsumer.java


注:本文中的org.apache.rocketmq.client.consumer.DefaultMQPushConsumer.setConsumeMessageBatchMaxSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。