io.openmessaging.rocketmq.utils.OMSUtil Java Examples

The following examples show how to use io.openmessaging.rocketmq.utils.OMSUtil. 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 File: ProducerImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.headers().put(MessageHeader.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
}
 
Example #2
Source File: ProducerImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.sysHeaders().put(Message.BuiltinKeys.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID), e);
    }
}
 
Example #3
Source File: ProducerImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.headers().put(MessageHeader.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
}
 
Example #4
Source File: ProducerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.sysHeaders().put(Message.BuiltinKeys.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID), e);
    }
}
 
Example #5
Source File: ProducerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.headers().put(MessageHeader.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
}
 
Example #6
Source File: ProducerImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.sysHeaders().put(Message.BuiltinKeys.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID), e);
    }
}
 
Example #7
Source File: PushConsumerImpl.java    From rocketmq-all-4.1.0-incubating with 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 #8
Source File: PullConsumerImpl.java    From rocketmq-all-4.1.0-incubating with 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 #9
Source File: SequenceProducerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Override
public void send(final Message message) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = OMSUtil.msgConvert((BytesMessage) message);
    try {
        Validators.checkMessage(rmqMessage, this.rocketmqProducer);
    } catch (MQClientException e) {
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
    msgCacheQueue.add(message);
}
 
Example #10
Source File: PushConsumerImpl.java    From DDMQ with 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 #11
Source File: PullConsumerImpl.java    From rocketmq with 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 File: PullConsumerImpl.java    From DDMQ with 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 #13
Source File: PushConsumerImpl.java    From rocketmq with 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 #14
Source File: SequenceProducerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void send(final Message message) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = OMSUtil.msgConvert((BytesMessage) message);
    try {
        Validators.checkMessage(rmqMessage, this.rocketmqProducer);
    } catch (MQClientException e) {
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
    msgCacheQueue.add(message);
}
 
Example #15
Source File: PushConsumerImpl.java    From rocketmq-read with 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 #16
Source File: PullConsumerImpl.java    From rocketmq-read with 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 #17
Source File: SequenceProducerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void send(final Message message) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = OMSUtil.msgConvert((BytesMessage) message);
    try {
        Validators.checkMessage(rmqMessage, this.rocketmqProducer);
    } catch (MQClientException e) {
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
    msgCacheQueue.add(message);
}
 
Example #18
Source File: PullConsumerImpl.java    From DDMQ with 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 #19
Source File: PushConsumerImpl.java    From rocketmq-4.3.0 with 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 #20
Source File: PushConsumerImpl.java    From DDMQ with 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 #21
Source File: PullConsumerImpl.java    From rocketmq-4.3.0 with 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 #22
Source File: PullConsumerImpl.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Override
public Message poll(final KeyValue properties) {
    MessageExt rmqMsg = localMessageCache.poll(properties);
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}
 
Example #23
Source File: MessagingAccessPointImpl.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Override
public SequenceProducer createSequenceProducer(KeyValue properties) {
    return new SequenceProducerImpl(OMSUtil.buildKeyValue(this.accessPointProperties, properties));
}
 
Example #24
Source File: MessagingAccessPointImpl.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Override
public Producer createProducer(KeyValue properties) {
    return new ProducerImpl(OMSUtil.buildKeyValue(this.accessPointProperties, properties));
}
 
Example #25
Source File: PullConsumerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
@Override
public Message poll() {
    MessageExt rmqMsg = localMessageCache.poll();
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}
 
Example #26
Source File: PullConsumerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
@Override
public Message poll(final KeyValue properties) {
    MessageExt rmqMsg = localMessageCache.poll(properties);
    return rmqMsg == null ? null : OMSUtil.msgConvert(rmqMsg);
}
 
Example #27
Source File: MessagingAccessPointImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
@Override
public Producer createProducer(KeyValue properties) {
    return new ProducerImpl(OMSUtil.buildKeyValue(this.accessPointProperties, properties));
}
 
Example #28
Source File: MessagingAccessPointImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
@Override
public SequenceProducer createSequenceProducer(KeyValue properties) {
    return new SequenceProducerImpl(OMSUtil.buildKeyValue(this.accessPointProperties, properties));
}
 
Example #29
Source File: MessagingAccessPointImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
@Override
public PushConsumer createPushConsumer(KeyValue properties) {
    return new PushConsumerImpl(OMSUtil.buildKeyValue(this.accessPointProperties, properties));
}
 
Example #30
Source File: MessagingAccessPointImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer createPullConsumer(String queueName, KeyValue properties) {
    return new PullConsumerImpl(queueName, OMSUtil.buildKeyValue(this.accessPointProperties, properties));
}