Search in sources :

Example 6 with DefaultMQProducer

use of com.alibaba.rocketmq.client.producer.DefaultMQProducer in project warn-report by saaavsaaa.

the class ProducerDouble method send.

public boolean send(final Message msg) {
    if (producers.isEmpty()) {
        System.out.println("case : Producer send error, reason : there isn't producer which could be used");
        throw new IllegalArgumentException(" there isn't producer which could be used  ! ");
    }
    DefaultMQProducer errorProducer = null;
    for (DefaultMQProducer one : producers) {
        try {
            SendResult sendResult = one.send(msg);
            System.out.println(String.format("==============ip : %s, send NamesrvAddr : %s, send key: %s, topic :%s", one.getClientIP(), one.getNamesrvAddr(), msg.getKeys(), msg.getTopic()));
            if (sendResult != null && sendResult.getSendStatus() != SendStatus.SEND_OK) {
                errorSendeds.add(msg);
            }
        } catch (Exception e) {
            System.out.println("reason : producer send error" + e.getMessage());
            if (errorProducer == null) {
                errorProducer = one;
            } else {
                return false;
            }
        }
    }
    if (errorProducer != null) {
        errorSendeds.add(msg);
    }
    return true;
}
Also used : SendResult(com.alibaba.rocketmq.client.producer.SendResult) DefaultMQProducer(com.alibaba.rocketmq.client.producer.DefaultMQProducer) MQClientException(com.alibaba.rocketmq.client.exception.MQClientException)

Example 7 with DefaultMQProducer

use of com.alibaba.rocketmq.client.producer.DefaultMQProducer in project warn-report by saaavsaaa.

the class ProducerSingle method init.

@Override
public void init(List<String> addresses, String producerGroup) {
    if (addresses == null || addresses.isEmpty()) {
        System.out.println("case : Producer init error, reason : the arg addresses should have value");
        throw new IllegalArgumentException(" the arg addresses should have value ! ");
    }
    String srvAddrs = addresses.get(0);
    if (addresses.size() > 1) {
        for (int i = 1; i < addresses.size(); i++) {
            srvAddrs += new StringBuilder(";").append(addresses.get(i)).toString();
        }
    }
    srvAddrs = "192.168.1.45:9876";
    System.out.println("srvAddrs : " + srvAddrs);
    producer = new DefaultMQProducer(producerGroup);
    producer.setInstanceName(Long.toString(System.currentTimeMillis()));
    producer.setNamesrvAddr(srvAddrs);
    producer.setCompressMsgBodyOverHowmuch(Integer.MAX_VALUE);
}
Also used : DefaultMQProducer(com.alibaba.rocketmq.client.producer.DefaultMQProducer)

Example 8 with DefaultMQProducer

use of com.alibaba.rocketmq.client.producer.DefaultMQProducer in project warn-report by saaavsaaa.

the class ProducerCluter method buildProducer.

private DefaultMQProducer buildProducer(final String address, final String producerGroup) throws MQClientException {
    DefaultMQProducer producer = new DefaultMQProducer(producerGroup);
    producer.setInstanceName(Long.toString(System.currentTimeMillis()));
    producer.setNamesrvAddr(address);
    producer.setCompressMsgBodyOverHowmuch(Integer.MAX_VALUE);
    producer.start();
    return producer;
}
Also used : DefaultMQProducer(com.alibaba.rocketmq.client.producer.DefaultMQProducer)

Example 9 with DefaultMQProducer

use of com.alibaba.rocketmq.client.producer.DefaultMQProducer in project warn-report by saaavsaaa.

the class ProducerDouble method buildProducer.

private DefaultMQProducer buildProducer(final String address, final String producerGroup) {
    DefaultMQProducer producer = new DefaultMQProducer(producerGroup);
    String instance = Long.toString(System.currentTimeMillis()) + producerGroup;
    System.out.println(String.format("producer : %s, instance : %s", producerGroup, instance));
    producer.setInstanceName(instance);
    producer.setNamesrvAddr(address);
    producer.setCompressMsgBodyOverHowmuch(Integer.MAX_VALUE);
    return producer;
}
Also used : DefaultMQProducer(com.alibaba.rocketmq.client.producer.DefaultMQProducer)

Example 10 with DefaultMQProducer

use of com.alibaba.rocketmq.client.producer.DefaultMQProducer in project warn-report by saaavsaaa.

the class ProducerDouble method start.

public void start(final int repeatDelay, final int repeatPeriod) throws MQClientException {
    for (DefaultMQProducer one : producers) {
        one.start();
    }
    this.repeatDelay = repeatDelay;
    this.repeatPeriod = repeatPeriod;
    repeat();
}
Also used : DefaultMQProducer(com.alibaba.rocketmq.client.producer.DefaultMQProducer)

Aggregations

DefaultMQProducer (com.alibaba.rocketmq.client.producer.DefaultMQProducer)11 MQClientException (com.alibaba.rocketmq.client.exception.MQClientException)5 Message (com.alibaba.rocketmq.common.message.Message)5 MQBrokerException (com.alibaba.rocketmq.client.exception.MQBrokerException)4 RemotingException (com.alibaba.rocketmq.remoting.exception.RemotingException)4 DefaultMQPushConsumer (com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer)3 ConsumeConcurrentlyContext (com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext)3 ConsumeConcurrentlyStatus (com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus)3 ConsumeOrderlyContext (com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyContext)3 ConsumeOrderlyStatus (com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyStatus)3 MessageListenerConcurrently (com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently)3 MessageListenerOrderly (com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly)3 MessageExt (com.alibaba.rocketmq.common.message.MessageExt)3 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 SendResult (com.alibaba.rocketmq.client.producer.SendResult)1 ConsoleLogger (com.creditease.monitor.log.ConsoleLogger)1 RocketmqHookProxy (com.creditease.uav.hook.rocketmq.RocketmqHookProxy)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1