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;
}
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);
}
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;
}
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;
}
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();
}
Aggregations