use of org.apache.rocketmq.client.producer.DefaultMQProducer in project ignite by apache.
the class RocketMQStreamerTest method produceData.
/**
* Adds data to RocketMQ.
*
* @throws Exception If fails.
*/
private void produceData() throws Exception {
initTopic(TOPIC_NAME, TEST_IP + ":" + NAME_SERVER_PORT);
DefaultMQProducer producer = new DefaultMQProducer("testProducerGrp");
producer.setNamesrvAddr(TEST_IP + ":" + NAME_SERVER_PORT);
try {
producer.start();
for (int i = 0; i < EVT_NUM; i++) producer.send(new Message(TOPIC_NAME, "", String.valueOf(i).getBytes("UTF-8")));
} catch (Exception e) {
throw new Exception(e);
} finally {
producer.shutdown();
}
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq-externals by apache.
the class ProducerTest method main.
public static void main(String[] args) {
DefaultMQProducer producer = new DefaultMQProducer("p001");
producer.setNamesrvAddr("localhost:9876");
try {
producer.start();
} catch (MQClientException e) {
e.printStackTrace();
}
for (int i = 0; i < 10000; i++) {
Message msg = new Message("flink-source2", "", "id_" + i, ("country_X province_" + i).getBytes());
try {
producer.send(msg);
} catch (MQClientException e) {
e.printStackTrace();
} catch (RemotingException e) {
e.printStackTrace();
} catch (MQBrokerException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("send " + i);
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq-externals by apache.
the class RocketMQSink method start.
@Override
public synchronized void start() {
producer = new DefaultMQProducer(producerGroup);
producer.setNamesrvAddr(nameServer);
try {
producer.start();
} catch (MQClientException e) {
sinkCounter.incrementConnectionFailedCount();
log.error("RocketMQ producer start failed", e);
throw new FlumeException("Failed to start RocketMQ producer", e);
}
sinkCounter.incrementConnectionCreatedCount();
sinkCounter.start();
super.start();
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq-externals by apache.
the class JmsClientIT method testConfigInURI.
@Test
public void testConfigInURI() throws Exception {
JmsBaseConnectionFactory connectionFactory = new JmsBaseConnectionFactory(new URI(String.format("rocketmq://xxx?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s", CommonConstant.PRODUCERID, producerId, CommonConstant.CONSUMERID, consumerId, CommonConstant.NAMESERVER, nameServer, CommonConstant.CONSUME_THREAD_NUMS, consumeThreadNums, CommonConstant.SEND_TIMEOUT_MILLIS, 10 * 1000, CommonConstant.INSTANCE_NAME, "JMS_TEST")));
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
try {
Destination destination = session.createTopic(topic + ":" + messageType);
session.createConsumer(destination);
session.createProducer(destination);
DefaultMQPushConsumer rmqPushConsumer = (DefaultMQPushConsumer) getRMQPushConsumerExt(consumerId).getConsumer();
Assert.assertNotNull(rmqPushConsumer);
Assert.assertEquals(consumerId, rmqPushConsumer.getConsumerGroup());
Assert.assertEquals("JMS_TEST", rmqPushConsumer.getInstanceName());
Assert.assertEquals(consumeThreadNums, rmqPushConsumer.getConsumeThreadMax());
Assert.assertEquals(consumeThreadNums, rmqPushConsumer.getConsumeThreadMin());
Assert.assertEquals(nameServer, rmqPushConsumer.getNamesrvAddr());
DefaultMQProducer mqProducer = (DefaultMQProducer) JmsTestUtil.getMQProducer(producerId);
Assert.assertNotNull(mqProducer);
Assert.assertEquals(producerId, mqProducer.getProducerGroup());
Assert.assertEquals("JMS_TEST", mqProducer.getInstanceName());
Assert.assertEquals(10 * 1000, mqProducer.getSendMsgTimeout());
Assert.assertEquals(nameServer, mqProducer.getNamesrvAddr());
Thread.sleep(2000);
} finally {
connection.close();
}
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq-externals by apache.
the class RocketMQServerMock method prepareDataTo.
public void prepareDataTo(String topic, int times) throws Exception {
// publish test message
DefaultMQProducer producer = new DefaultMQProducer(producerGroup);
producer.setNamesrvAddr(nameserverAddr);
String sendMsg = "\"Hello Rocket\"" + "," + DateFormatUtils.format(new Date(), "yyyy-MM-DD hh:mm:ss");
try {
producer.start();
for (int i = 0; i < times; i++) {
producer.send(new Message(topic, sendMsg.getBytes("UTF-8")));
}
} catch (Exception e) {
throw new MQClientException("Failed to publish messages", e);
} finally {
producer.shutdown();
}
}
Aggregations