本文整理汇总了Java中org.apache.rocketmq.client.consumer.DefaultMQPushConsumer.setConsumeThreadMin方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMQPushConsumer.setConsumeThreadMin方法的具体用法?Java DefaultMQPushConsumer.setConsumeThreadMin怎么用?Java DefaultMQPushConsumer.setConsumeThreadMin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.rocketmq.client.consumer.DefaultMQPushConsumer
的用法示例。
在下文中一共展示了DefaultMQPushConsumer.setConsumeThreadMin方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: receiveTransactionMessage
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
/**
* 接收消息
*/
public void receiveTransactionMessage() {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(RocketMQConfiguration.ROCKETMQ_GROUP);
consumer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
consumer.setVipChannelEnabled(false);
consumer.setConsumeThreadMax(20);
consumer.setConsumeThreadMin(10);
try {
consumer.subscribe(RocketMQConfiguration.ROCKETMQ_TOPIC, "transaction");
//程序第一次启动从消息队列头取数据
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.registerMessageListener(
new MessageListenerConcurrently() {
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext Context) {
Message msg = list.get(0);
System.out.println(msg.toString());
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
}
);
consumer.start();
} catch (MQClientException e) {
e.printStackTrace();
}
}
示例2: initRocketMQPushConsumer
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
private void initRocketMQPushConsumer() throws MQClientException {
Assert.notNull(getConsumerGroup(), "Property 'consumerGroup' is required");
Assert.notEmpty(subscribeTopicTags(), "subscribeTopicTags method can't be empty");
consumer = new DefaultMQPushConsumer(getConsumerGroup());
if (consumeThreadMax != null) {
consumer.setConsumeThreadMax(consumeThreadMax);
}
if (consumeThreadMax != null && consumeThreadMax < consumer.getConsumeThreadMin()) {
consumer.setConsumeThreadMin(consumeThreadMax);
}
consumer.setConsumeFromWhere(consumeFromWhere);
consumer.setMessageModel(messageModel);
switch (consumeMode) {
case Orderly:
consumer.setMessageListener(new DefaultMessageListenerOrderly());
break;
case CONCURRENTLY:
consumer.setMessageListener(new DefaultMessageListenerConcurrently());
break;
default:
throw new IllegalArgumentException("Property 'consumeMode' was wrong.");
}
}
示例3: checkConfigTest
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
@Test
public void checkConfigTest() throws MQClientException {
//test type
thrown.expect(MQClientException.class);
//test message
thrown.expectMessage("consumeThreadMin (10) is larger than consumeThreadMax (9)");
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("test_consumer_group");
consumer.setConsumeThreadMin(10);
consumer.setConsumeThreadMax(9);
consumer.registerMessageListener(new MessageListenerConcurrently() {
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
ConsumeConcurrentlyContext context) {
System.out.println(" Receive New Messages: " + msgs);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
DefaultMQPushConsumerImpl defaultMQPushConsumerImpl = new DefaultMQPushConsumerImpl(consumer, null);
defaultMQPushConsumerImpl.start();
}
示例4: receiveMessage
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
/**
* 接收消息
*/
public void receiveMessage() {
//获取消费者
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(RocketMQConfiguration.ROCKETMQ_GROUP);
//设置namesrv地址【可以通过环境变量、运行参数来设置】
consumer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
consumer.setVipChannelEnabled(false);
//设置消费者最大最小线程
consumer.setConsumeThreadMax(20);
consumer.setConsumeThreadMin(10);
try {
//订阅主题下的所有tag
consumer.subscribe(RocketMQConfiguration.ROCKETMQ_TOPIC, "*");
//程序第一次启动从消息队列头取数据
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
//随机获取队列中的消息,相应的是MessageListenerOrderly 按照消息发送顺序来接受消息
consumer.registerMessageListener(
new MessageListenerConcurrently() {
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext Context) {
Message msg = list.get(0);
System.out.println(msg.toString());
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
}
);
//启动消费端 线程会一直挂起 等待消息的到来
consumer.start();
} catch (MQClientException e) {
e.printStackTrace();
}
}
示例5: initRocketMQPushConsumer
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
private void initRocketMQPushConsumer() throws MQClientException {
Assert.notNull(rocketMQListener, "Property 'rocketMQListener' is required");
Assert.notNull(consumerGroup, "Property 'consumerGroup' is required");
Assert.notNull(nameServer, "Property 'nameServer' is required");
Assert.notNull(topic, "Property 'topic' is required");
consumer = new DefaultMQPushConsumer(consumerGroup);
consumer.setNamesrvAddr(nameServer);
consumer.setConsumeThreadMax(consumeThreadMax);
if (consumeThreadMax < consumer.getConsumeThreadMin()) {
consumer.setConsumeThreadMin(consumeThreadMax);
}
consumer.setPullThresholdForTopic(pullThresholdForTopic);
consumer.setPullThresholdSizeForTopic(pullThresholdSizeForTopic);
consumer.setMessageModel(messageModel);
switch (selectorType) {
case TAG:
consumer.subscribe(topic, selectorExpress);
break;
case SQL92:
consumer.subscribe(topic, MessageSelector.bySql(selectorExpress));
break;
default:
throw new IllegalArgumentException("Property 'selectorType' was wrong.");
}
switch (consumeMode) {
case ORDERLY:
consumer.setMessageListener(new DefaultMessageListenerOrderly());
break;
case CONCURRENTLY:
consumer.setMessageListener(new DefaultMessageListenerConcurrently());
break;
default:
throw new IllegalArgumentException("Property 'consumeMode' was wrong.");
}
// provide an entryway to custom setting RocketMQ consumer
if (rocketMQListener instanceof RocketMQPushConsumerLifecycleListener) {
((RocketMQPushConsumerLifecycleListener) rocketMQListener).prepareStart(consumer);
}
}
开发者ID:QianmiOpen,项目名称:spring-boot-starter-rocketmq,代码行数:47,代码来源:DefaultRocketMQListenerContainer.java