Java Code Examples for io.openmessaging.rocketmq.utils.BeanUtils

The following examples show how to use io.openmessaging.rocketmq.utils.BeanUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: DDMQ   Source File: AbstractOMSProducer.java    License: Apache License 2.0 6 votes vote down vote up
AbstractOMSProducer(final KeyValue properties) {
    this.properties = properties;
    this.rocketmqProducer = new DefaultMQProducer();
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String accessPoints = clientConfig.getOmsAccessPoints();
    if (accessPoints == null || accessPoints.isEmpty()) {
        throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
    }
    this.rocketmqProducer.setNamesrvAddr(accessPoints.replace(',', ';'));
    this.rocketmqProducer.setProducerGroup(clientConfig.getRmqProducerGroup());

    String producerId = buildInstanceName();
    this.rocketmqProducer.setSendMsgTimeout(clientConfig.getOmsOperationTimeout());
    this.rocketmqProducer.setInstanceName(producerId);
    this.rocketmqProducer.setMaxMessageSize(1024 * 1024 * 4);
    properties.put(PropertyKeys.PRODUCER_ID, producerId);
}
 
Example 2
Source Project: rocketmq-4.3.0   Source File: AbstractOMSProducer.java    License: Apache License 2.0 6 votes vote down vote up
AbstractOMSProducer(final KeyValue properties) {
    this.properties = properties;
    this.rocketmqProducer = new DefaultMQProducer();
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    if ("true".equalsIgnoreCase(System.getenv("OMS_RMQ_DIRECT_NAME_SRV"))) {
        String accessPoints = clientConfig.getAccessPoints();
        if (accessPoints == null || accessPoints.isEmpty()) {
            throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
        }

        this.rocketmqProducer.setNamesrvAddr(accessPoints.replace(',', ';'));
    }

    this.rocketmqProducer.setProducerGroup(clientConfig.getRmqProducerGroup());

    String producerId = buildInstanceName();
    this.rocketmqProducer.setSendMsgTimeout(clientConfig.getOperationTimeout());
    this.rocketmqProducer.setInstanceName(producerId);
    this.rocketmqProducer.setMaxMessageSize(1024 * 1024 * 4);
    this.rocketmqProducer.setLanguage(LanguageCode.OMS);
    properties.put(OMSBuiltinKeys.PRODUCER_ID, producerId);
}
 
Example 3
Source Project: rocketmq-read   Source File: AbstractOMSProducer.java    License: Apache License 2.0 6 votes vote down vote up
AbstractOMSProducer(final KeyValue properties) {
    this.properties = properties;
    this.rocketmqProducer = new DefaultMQProducer();
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    if ("true".equalsIgnoreCase(System.getenv("OMS_RMQ_DIRECT_NAME_SRV"))) {
        String accessPoints = clientConfig.getAccessPoints();
        if (accessPoints == null || accessPoints.isEmpty()) {
            throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
        }

        this.rocketmqProducer.setNamesrvAddr(accessPoints.replace(',', ';'));
    }

    this.rocketmqProducer.setProducerGroup(clientConfig.getRmqProducerGroup());

    String producerId = buildInstanceName();
    this.rocketmqProducer.setSendMsgTimeout(clientConfig.getOperationTimeout());
    this.rocketmqProducer.setInstanceName(producerId);
    this.rocketmqProducer.setMaxMessageSize(1024 * 1024 * 4);
    this.rocketmqProducer.setLanguage(LanguageCode.OMS);
    properties.put(OMSBuiltinKeys.PRODUCER_ID, producerId);
}
 
Example 4
Source Project: DDMQ   Source File: AbstractOMSProducer.java    License: Apache License 2.0 6 votes vote down vote up
AbstractOMSProducer(final KeyValue properties) {
    this.properties = properties;
    this.rocketmqProducer = new DefaultMQProducer();
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String accessPoints = clientConfig.getOmsAccessPoints();
    if (accessPoints == null || accessPoints.isEmpty()) {
        throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
    }
    this.rocketmqProducer.setNamesrvAddr(accessPoints.replace(',', ';'));
    this.rocketmqProducer.setProducerGroup(clientConfig.getRmqProducerGroup());

    String producerId = buildInstanceName();
    this.rocketmqProducer.setSendMsgTimeout(clientConfig.getOmsOperationTimeout());
    this.rocketmqProducer.setInstanceName(producerId);
    this.rocketmqProducer.setMaxMessageSize(1024 * 1024 * 4);
    properties.put(PropertyKeys.PRODUCER_ID, producerId);
}
 
Example 5
AbstractOMSProducer(final KeyValue properties) {
    this.properties = properties;
    this.rocketmqProducer = new DefaultMQProducer();
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String accessPoints = clientConfig.getOmsAccessPoints();
    if (accessPoints == null || accessPoints.isEmpty()) {
        throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
    }
    this.rocketmqProducer.setNamesrvAddr(accessPoints.replace(',', ';'));
    this.rocketmqProducer.setProducerGroup(clientConfig.getRmqProducerGroup());

    String producerId = buildInstanceName();
    this.rocketmqProducer.setSendMsgTimeout(clientConfig.getOmsOperationTimeout());
    this.rocketmqProducer.setInstanceName(producerId);
    this.rocketmqProducer.setMaxMessageSize(1024 * 1024 * 4);
    properties.put(PropertyKeys.PRODUCER_ID, producerId);
}
 
Example 6
Source Project: rocketmq   Source File: AbstractOMSProducer.java    License: Apache License 2.0 6 votes vote down vote up
AbstractOMSProducer(final KeyValue properties) {
    this.properties = properties;
    this.rocketmqProducer = new DefaultMQProducer();
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    if ("true".equalsIgnoreCase(System.getenv("OMS_RMQ_DIRECT_NAME_SRV"))) {
        String accessPoints = clientConfig.getAccessPoints();
        if (accessPoints == null || accessPoints.isEmpty()) {
            throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
        }

        this.rocketmqProducer.setNamesrvAddr(accessPoints.replace(',', ';'));
    }

    this.rocketmqProducer.setProducerGroup(clientConfig.getRmqProducerGroup());

    String producerId = buildInstanceName();
    this.rocketmqProducer.setSendMsgTimeout(clientConfig.getOperationTimeout());
    this.rocketmqProducer.setInstanceName(producerId);
    this.rocketmqProducer.setMaxMessageSize(1024 * 1024 * 4);
    this.rocketmqProducer.setLanguage(LanguageCode.OMS);
    properties.put(OMSBuiltinKeys.PRODUCER_ID, producerId);
}
 
Example 7
Source Project: DDMQ   Source File: PullConsumerImpl.java    License: Apache License 2.0 5 votes vote down vote up
public PullConsumerImpl(final String queueName, final KeyValue properties) {
    this.properties = properties;
    this.targetQueueName = queueName;

    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String consumerGroup = clientConfig.getRmqConsumerGroup();
    if (null == consumerGroup || consumerGroup.isEmpty()) {
        throw new OMSRuntimeException("-1", "Consumer Group is necessary for RocketMQ, please set it.");
    }
    pullConsumerScheduleService = new MQPullConsumerScheduleService(consumerGroup);

    this.rocketmqPullConsumer = pullConsumerScheduleService.getDefaultMQPullConsumer();

    String accessPoints = clientConfig.getOmsAccessPoints();
    if (accessPoints == null || accessPoints.isEmpty()) {
        throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
    }
    this.rocketmqPullConsumer.setNamesrvAddr(accessPoints.replace(',', ';'));

    this.rocketmqPullConsumer.setConsumerGroup(consumerGroup);

    int maxReDeliveryTimes = clientConfig.getRmqMaxRedeliveryTimes();
    this.rocketmqPullConsumer.setMaxReconsumeTimes(maxReDeliveryTimes);

    String consumerId = OMSUtil.buildInstanceName();
    this.rocketmqPullConsumer.setInstanceName(consumerId);
    properties.put(PropertyKeys.CONSUMER_ID, consumerId);

    this.localMessageCache = new LocalMessageCache(this.rocketmqPullConsumer, clientConfig);
}
 
Example 8
Source Project: DDMQ   Source File: PushConsumerImpl.java    License: Apache License 2.0 5 votes vote down vote up
public PushConsumerImpl(final KeyValue properties) {
    this.rocketmqPushConsumer = new DefaultMQPushConsumer();
    this.properties = properties;
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String accessPoints = clientConfig.getOmsAccessPoints();
    if (accessPoints == null || accessPoints.isEmpty()) {
        throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
    }
    this.rocketmqPushConsumer.setNamesrvAddr(accessPoints.replace(',', ';'));

    String consumerGroup = clientConfig.getRmqConsumerGroup();
    if (null == consumerGroup || consumerGroup.isEmpty()) {
        throw new OMSRuntimeException("-1", "Consumer Group is necessary for RocketMQ, please set it.");
    }
    this.rocketmqPushConsumer.setConsumerGroup(consumerGroup);
    this.rocketmqPushConsumer.setMaxReconsumeTimes(clientConfig.getRmqMaxRedeliveryTimes());
    this.rocketmqPushConsumer.setConsumeTimeout(clientConfig.getRmqMessageConsumeTimeout());
    this.rocketmqPushConsumer.setConsumeThreadMax(clientConfig.getRmqMaxConsumeThreadNums());
    this.rocketmqPushConsumer.setConsumeThreadMin(clientConfig.getRmqMinConsumeThreadNums());

    String consumerId = OMSUtil.buildInstanceName();
    this.rocketmqPushConsumer.setInstanceName(consumerId);
    properties.put(PropertyKeys.CONSUMER_ID, consumerId);

    this.rocketmqPushConsumer.registerMessageListener(new MessageListenerImpl());
}
 
Example 9
Source Project: rocketmq-4.3.0   Source File: PullConsumerImpl.java    License: Apache License 2.0 5 votes vote down vote up
public PullConsumerImpl(final KeyValue properties) {
    this.properties = properties;
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String consumerGroup = clientConfig.getConsumerId();
    if (null == consumerGroup || consumerGroup.isEmpty()) {
        throw new OMSRuntimeException("-1", "Consumer Group is necessary for RocketMQ, please set it.");
    }
    pullConsumerScheduleService = new MQPullConsumerScheduleService(consumerGroup);

    this.rocketmqPullConsumer = pullConsumerScheduleService.getDefaultMQPullConsumer();

    if ("true".equalsIgnoreCase(System.getenv("OMS_RMQ_DIRECT_NAME_SRV"))) {
        String accessPoints = clientConfig.getAccessPoints();
        if (accessPoints == null || accessPoints.isEmpty()) {
            throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
        }
        this.rocketmqPullConsumer.setNamesrvAddr(accessPoints.replace(',', ';'));
    }

    this.rocketmqPullConsumer.setConsumerGroup(consumerGroup);

    int maxReDeliveryTimes = clientConfig.getRmqMaxRedeliveryTimes();
    this.rocketmqPullConsumer.setMaxReconsumeTimes(maxReDeliveryTimes);

    String consumerId = OMSUtil.buildInstanceName();
    this.rocketmqPullConsumer.setInstanceName(consumerId);
    properties.put(OMSBuiltinKeys.CONSUMER_ID, consumerId);

    this.rocketmqPullConsumer.setLanguage(LanguageCode.OMS);

    this.localMessageCache = new LocalMessageCache(this.rocketmqPullConsumer, clientConfig);
}
 
Example 10
Source Project: rocketmq-4.3.0   Source File: PushConsumerImpl.java    License: Apache License 2.0 5 votes vote down vote up
public PushConsumerImpl(final KeyValue properties) {
    this.rocketmqPushConsumer = new DefaultMQPushConsumer();
    this.properties = properties;
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    if ("true".equalsIgnoreCase(System.getenv("OMS_RMQ_DIRECT_NAME_SRV"))) {
        String accessPoints = clientConfig.getAccessPoints();
        if (accessPoints == null || accessPoints.isEmpty()) {
            throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
        }
        this.rocketmqPushConsumer.setNamesrvAddr(accessPoints.replace(',', ';'));
    }

    String consumerGroup = clientConfig.getConsumerId();
    if (null == consumerGroup || consumerGroup.isEmpty()) {
        throw new OMSRuntimeException("-1", "Consumer Group is necessary for RocketMQ, please set it.");
    }
    this.rocketmqPushConsumer.setConsumerGroup(consumerGroup);
    this.rocketmqPushConsumer.setMaxReconsumeTimes(clientConfig.getRmqMaxRedeliveryTimes());
    this.rocketmqPushConsumer.setConsumeTimeout(clientConfig.getRmqMessageConsumeTimeout());
    this.rocketmqPushConsumer.setConsumeThreadMax(clientConfig.getRmqMaxConsumeThreadNums());
    this.rocketmqPushConsumer.setConsumeThreadMin(clientConfig.getRmqMinConsumeThreadNums());

    String consumerId = OMSUtil.buildInstanceName();
    this.rocketmqPushConsumer.setInstanceName(consumerId);
    properties.put(OMSBuiltinKeys.CONSUMER_ID, consumerId);
    this.rocketmqPushConsumer.setLanguage(LanguageCode.OMS);

    this.rocketmqPushConsumer.registerMessageListener(new MessageListenerImpl());
}
 
Example 11
Source Project: rocketmq-read   Source File: PullConsumerImpl.java    License: Apache License 2.0 5 votes vote down vote up
public PullConsumerImpl(final KeyValue properties) {
    this.properties = properties;
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String consumerGroup = clientConfig.getConsumerId();
    if (null == consumerGroup || consumerGroup.isEmpty()) {
        throw new OMSRuntimeException("-1", "Consumer Group is necessary for RocketMQ, please set it.");
    }
    pullConsumerScheduleService = new MQPullConsumerScheduleService(consumerGroup);

    this.rocketmqPullConsumer = pullConsumerScheduleService.getDefaultMQPullConsumer();

    if ("true".equalsIgnoreCase(System.getenv("OMS_RMQ_DIRECT_NAME_SRV"))) {
        String accessPoints = clientConfig.getAccessPoints();
        if (accessPoints == null || accessPoints.isEmpty()) {
            throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
        }
        this.rocketmqPullConsumer.setNamesrvAddr(accessPoints.replace(',', ';'));
    }

    this.rocketmqPullConsumer.setConsumerGroup(consumerGroup);

    int maxReDeliveryTimes = clientConfig.getRmqMaxRedeliveryTimes();
    this.rocketmqPullConsumer.setMaxReconsumeTimes(maxReDeliveryTimes);

    String consumerId = OMSUtil.buildInstanceName();
    this.rocketmqPullConsumer.setInstanceName(consumerId);
    properties.put(OMSBuiltinKeys.CONSUMER_ID, consumerId);

    this.rocketmqPullConsumer.setLanguage(LanguageCode.OMS);

    this.localMessageCache = new LocalMessageCache(this.rocketmqPullConsumer, clientConfig);
}
 
Example 12
Source Project: rocketmq-read   Source File: PushConsumerImpl.java    License: Apache License 2.0 5 votes vote down vote up
public PushConsumerImpl(final KeyValue properties) {
    this.rocketmqPushConsumer = new DefaultMQPushConsumer();
    this.properties = properties;
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    if ("true".equalsIgnoreCase(System.getenv("OMS_RMQ_DIRECT_NAME_SRV"))) {
        String accessPoints = clientConfig.getAccessPoints();
        if (accessPoints == null || accessPoints.isEmpty()) {
            throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
        }
        this.rocketmqPushConsumer.setNamesrvAddr(accessPoints.replace(',', ';'));
    }

    String consumerGroup = clientConfig.getConsumerId();
    if (null == consumerGroup || consumerGroup.isEmpty()) {
        throw new OMSRuntimeException("-1", "Consumer Group is necessary for RocketMQ, please set it.");
    }
    this.rocketmqPushConsumer.setConsumerGroup(consumerGroup);
    this.rocketmqPushConsumer.setMaxReconsumeTimes(clientConfig.getRmqMaxRedeliveryTimes());
    this.rocketmqPushConsumer.setConsumeTimeout(clientConfig.getRmqMessageConsumeTimeout());
    this.rocketmqPushConsumer.setConsumeThreadMax(clientConfig.getRmqMaxConsumeThreadNums());
    this.rocketmqPushConsumer.setConsumeThreadMin(clientConfig.getRmqMinConsumeThreadNums());

    String consumerId = OMSUtil.buildInstanceName();
    this.rocketmqPushConsumer.setInstanceName(consumerId);
    properties.put(OMSBuiltinKeys.CONSUMER_ID, consumerId);
    this.rocketmqPushConsumer.setLanguage(LanguageCode.OMS);

    this.rocketmqPushConsumer.registerMessageListener(new MessageListenerImpl());
}
 
Example 13
Source Project: DDMQ   Source File: PullConsumerImpl.java    License: Apache License 2.0 5 votes vote down vote up
public PullConsumerImpl(final String queueName, final KeyValue properties) {
    this.properties = properties;
    this.targetQueueName = queueName;

    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String consumerGroup = clientConfig.getRmqConsumerGroup();
    if (null == consumerGroup || consumerGroup.isEmpty()) {
        throw new OMSRuntimeException("-1", "Consumer Group is necessary for RocketMQ, please set it.");
    }
    pullConsumerScheduleService = new MQPullConsumerScheduleService(consumerGroup);

    this.rocketmqPullConsumer = pullConsumerScheduleService.getDefaultMQPullConsumer();

    String accessPoints = clientConfig.getOmsAccessPoints();
    if (accessPoints == null || accessPoints.isEmpty()) {
        throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
    }
    this.rocketmqPullConsumer.setNamesrvAddr(accessPoints.replace(',', ';'));

    this.rocketmqPullConsumer.setConsumerGroup(consumerGroup);

    int maxReDeliveryTimes = clientConfig.getRmqMaxRedeliveryTimes();
    this.rocketmqPullConsumer.setMaxReconsumeTimes(maxReDeliveryTimes);

    String consumerId = OMSUtil.buildInstanceName();
    this.rocketmqPullConsumer.setInstanceName(consumerId);
    properties.put(PropertyKeys.CONSUMER_ID, consumerId);

    this.localMessageCache = new LocalMessageCache(this.rocketmqPullConsumer, clientConfig);
}
 
Example 14
Source Project: DDMQ   Source File: PushConsumerImpl.java    License: Apache License 2.0 5 votes vote down vote up
public PushConsumerImpl(final KeyValue properties) {
    this.rocketmqPushConsumer = new DefaultMQPushConsumer();
    this.properties = properties;
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String accessPoints = clientConfig.getOmsAccessPoints();
    if (accessPoints == null || accessPoints.isEmpty()) {
        throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
    }
    this.rocketmqPushConsumer.setNamesrvAddr(accessPoints.replace(',', ';'));

    String consumerGroup = clientConfig.getRmqConsumerGroup();
    if (null == consumerGroup || consumerGroup.isEmpty()) {
        throw new OMSRuntimeException("-1", "Consumer Group is necessary for RocketMQ, please set it.");
    }
    this.rocketmqPushConsumer.setConsumerGroup(consumerGroup);
    this.rocketmqPushConsumer.setMaxReconsumeTimes(clientConfig.getRmqMaxRedeliveryTimes());
    this.rocketmqPushConsumer.setConsumeTimeout(clientConfig.getRmqMessageConsumeTimeout());
    this.rocketmqPushConsumer.setConsumeThreadMax(clientConfig.getRmqMaxConsumeThreadNums());
    this.rocketmqPushConsumer.setConsumeThreadMin(clientConfig.getRmqMinConsumeThreadNums());

    String consumerId = OMSUtil.buildInstanceName();
    this.rocketmqPushConsumer.setInstanceName(consumerId);
    properties.put(PropertyKeys.CONSUMER_ID, consumerId);

    this.rocketmqPushConsumer.registerMessageListener(new MessageListenerImpl());
}
 
Example 15
public PullConsumerImpl(final String queueName, final KeyValue properties) {
    this.properties = properties;
    this.targetQueueName = queueName;

    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String consumerGroup = clientConfig.getRmqConsumerGroup();
    if (null == consumerGroup || consumerGroup.isEmpty()) {
        throw new OMSRuntimeException("-1", "Consumer Group is necessary for RocketMQ, please set it.");
    }
    pullConsumerScheduleService = new MQPullConsumerScheduleService(consumerGroup);

    this.rocketmqPullConsumer = pullConsumerScheduleService.getDefaultMQPullConsumer();

    String accessPoints = clientConfig.getOmsAccessPoints();
    if (accessPoints == null || accessPoints.isEmpty()) {
        throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
    }
    this.rocketmqPullConsumer.setNamesrvAddr(accessPoints.replace(',', ';'));

    this.rocketmqPullConsumer.setConsumerGroup(consumerGroup);

    int maxReDeliveryTimes = clientConfig.getRmqMaxRedeliveryTimes();
    this.rocketmqPullConsumer.setMaxReconsumeTimes(maxReDeliveryTimes);

    String consumerId = OMSUtil.buildInstanceName();
    this.rocketmqPullConsumer.setInstanceName(consumerId);
    properties.put(PropertyKeys.CONSUMER_ID, consumerId);

    this.localMessageCache = new LocalMessageCache(this.rocketmqPullConsumer, clientConfig);
}
 
Example 16
public PushConsumerImpl(final KeyValue properties) {
    this.rocketmqPushConsumer = new DefaultMQPushConsumer();
    this.properties = properties;
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String accessPoints = clientConfig.getOmsAccessPoints();
    if (accessPoints == null || accessPoints.isEmpty()) {
        throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
    }
    this.rocketmqPushConsumer.setNamesrvAddr(accessPoints.replace(',', ';'));

    String consumerGroup = clientConfig.getRmqConsumerGroup();
    if (null == consumerGroup || consumerGroup.isEmpty()) {
        throw new OMSRuntimeException("-1", "Consumer Group is necessary for RocketMQ, please set it.");
    }
    this.rocketmqPushConsumer.setConsumerGroup(consumerGroup);
    this.rocketmqPushConsumer.setMaxReconsumeTimes(clientConfig.getRmqMaxRedeliveryTimes());
    this.rocketmqPushConsumer.setConsumeTimeout(clientConfig.getRmqMessageConsumeTimeout());
    this.rocketmqPushConsumer.setConsumeThreadMax(clientConfig.getRmqMaxConsumeThreadNums());
    this.rocketmqPushConsumer.setConsumeThreadMin(clientConfig.getRmqMinConsumeThreadNums());

    String consumerId = OMSUtil.buildInstanceName();
    this.rocketmqPushConsumer.setInstanceName(consumerId);
    properties.put(PropertyKeys.CONSUMER_ID, consumerId);

    this.rocketmqPushConsumer.registerMessageListener(new MessageListenerImpl());
}
 
Example 17
Source Project: rocketmq   Source File: PullConsumerImpl.java    License: Apache License 2.0 5 votes vote down vote up
public PullConsumerImpl(final KeyValue properties) {
    this.properties = properties;
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String consumerGroup = clientConfig.getConsumerId();
    if (null == consumerGroup || consumerGroup.isEmpty()) {
        throw new OMSRuntimeException("-1", "Consumer Group is necessary for RocketMQ, please set it.");
    }
    pullConsumerScheduleService = new MQPullConsumerScheduleService(consumerGroup);

    this.rocketmqPullConsumer = pullConsumerScheduleService.getDefaultMQPullConsumer();

    if ("true".equalsIgnoreCase(System.getenv("OMS_RMQ_DIRECT_NAME_SRV"))) {
        String accessPoints = clientConfig.getAccessPoints();
        if (accessPoints == null || accessPoints.isEmpty()) {
            throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
        }
        this.rocketmqPullConsumer.setNamesrvAddr(accessPoints.replace(',', ';'));
    }

    this.rocketmqPullConsumer.setConsumerGroup(consumerGroup);

    int maxReDeliveryTimes = clientConfig.getRmqMaxRedeliveryTimes();
    this.rocketmqPullConsumer.setMaxReconsumeTimes(maxReDeliveryTimes);

    String consumerId = OMSUtil.buildInstanceName();
    this.rocketmqPullConsumer.setInstanceName(consumerId);
    properties.put(OMSBuiltinKeys.CONSUMER_ID, consumerId);

    this.rocketmqPullConsumer.setLanguage(LanguageCode.OMS);

    this.localMessageCache = new LocalMessageCache(this.rocketmqPullConsumer, clientConfig);
}
 
Example 18
Source Project: rocketmq   Source File: PushConsumerImpl.java    License: Apache License 2.0 5 votes vote down vote up
public PushConsumerImpl(final KeyValue properties) {
    this.rocketmqPushConsumer = new DefaultMQPushConsumer();
    this.properties = properties;
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    if ("true".equalsIgnoreCase(System.getenv("OMS_RMQ_DIRECT_NAME_SRV"))) {
        String accessPoints = clientConfig.getAccessPoints();
        if (accessPoints == null || accessPoints.isEmpty()) {
            throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
        }
        this.rocketmqPushConsumer.setNamesrvAddr(accessPoints.replace(',', ';'));
    }

    String consumerGroup = clientConfig.getConsumerId();
    if (null == consumerGroup || consumerGroup.isEmpty()) {
        throw new OMSRuntimeException("-1", "Consumer Group is necessary for RocketMQ, please set it.");
    }
    this.rocketmqPushConsumer.setConsumerGroup(consumerGroup);
    this.rocketmqPushConsumer.setMaxReconsumeTimes(clientConfig.getRmqMaxRedeliveryTimes());
    this.rocketmqPushConsumer.setConsumeTimeout(clientConfig.getRmqMessageConsumeTimeout());
    this.rocketmqPushConsumer.setConsumeThreadMax(clientConfig.getRmqMaxConsumeThreadNums());
    this.rocketmqPushConsumer.setConsumeThreadMin(clientConfig.getRmqMinConsumeThreadNums());

    String consumerId = OMSUtil.buildInstanceName();
    this.rocketmqPushConsumer.setInstanceName(consumerId);
    properties.put(OMSBuiltinKeys.CONSUMER_ID, consumerId);
    this.rocketmqPushConsumer.setLanguage(LanguageCode.OMS);

    this.rocketmqPushConsumer.registerMessageListener(new MessageListenerImpl());
}