@Override public void cleanup() { if (producer != null) { producer.shutdown(); } } }
@Override public synchronized void shutdown() { if (this.started) { this.rocketmqProducer.shutdown(); } this.started = false; }
@Override public void shutdown() { producer.shutdown(); }
public void shutdown() { producer.shutdown(); }
@Override public void stop() { if (producer != null) { producer.shutdown(); } running = false; }
/** * Stops the RocketMQ producer. */ public void stop() { producer.shutdown(); } }
@Override public void stop() { logger.info("## Stop RocketMQ producer##"); this.defaultMQProducer.shutdown(); } }
@Override public void shutdown() { this.stopped = true; this.traceExecuter.shutdown(); if (isStarted.get()) { traceProducer.shutdown(); } this.removeShutdownHook(); }
@Override public void shutdown() { super.shutdown(); this.defaultMQProducerImpl.destroyTransactionEnv(); }
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException { final DefaultMQProducer producer = new DefaultMQProducer("PID_SMSC", rpcHook); producer.setInstanceName("PID_SMSC_" + System.currentTimeMillis()); try { producer.start(); String brokerName = commandLine.getOptionValue('b').trim(); int messageSize = commandLine.hasOption('s') ? Integer.parseInt(commandLine.getOptionValue('s')) : 128; int count = commandLine.hasOption('c') ? Integer.parseInt(commandLine.getOptionValue('c')) : 50; producer.send(buildMessage(brokerName, 16)); for (int i = 0; i < count; i++) { long begin = System.currentTimeMillis(); SendResult result = producer.send(buildMessage(brokerName, messageSize)); System.out.printf("rt:" + (System.currentTimeMillis() - begin) + "ms, SendResult=%s", result); } } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { producer.shutdown(); } } }
public static void main(String[] args) throws MQClientException, InterruptedException { DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName"); producer.start(); for (int i = 0; i < 128; i++) try { { Message msg = new Message("TopicTest", "TagA", "OrderID188", "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET)); SendResult sendResult = producer.send(msg); System.out.printf("%s%n", sendResult); } } catch (Exception e) { e.printStackTrace(); } producer.shutdown(); } }
public static void main(String[] args) throws MQClientException, InterruptedException { DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName",true); producer.start(); for (int i = 0; i < 128; i++) try { { Message msg = new Message("TopicTest", "TagA", "OrderID188", "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET)); SendResult sendResult = producer.send(msg); System.out.printf("%s%n", sendResult); } } catch (Exception e) { e.printStackTrace(); } producer.shutdown(); } }
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQProducer.shutdown(); defaultMQAdminExt.shutdown();
public static void main(String[] args) throws Exception { // Instantiate with a producer group name. DefaultMQProducer producer = new DefaultMQProducer(Constants.TEST_GROUP_NAME); // Launch the instance. producer.start(); for (int i = 0; i < 1000; i++) { // Create a message instance, specifying topic, tag and message body. Message msg = new Message(Constants.TEST_TOPIC_NAME, "TagA", ("Hello RocketMQ From Sentinel " + i).getBytes(RemotingHelper.DEFAULT_CHARSET) ); // Call send message to deliver message to one of brokers. SendResult sendResult = producer.send(msg); System.out.printf("%s%n", sendResult); } // Shut down once the producer instance is not longer in use. producer.shutdown(); } }
public static void producer() throws MQClientException { DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName", getAclRPCHook()); producer.setNamesrvAddr("127.0.0.1:9876"); producer.start(); for (int i = 0; i < 128; i++) try { { Message msg = new Message("TopicTest", "TagA", "OrderID188", "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET)); SendResult sendResult = producer.send(msg); System.out.printf("%s%n", sendResult); } } catch (Exception e) { e.printStackTrace(); } producer.shutdown(); }
producer.shutdown();
@Override public synchronized void stop() { producer.shutdown(); sinkCounter.incrementConnectionClosedCount(); sinkCounter.stop(); super.stop(); }
public static void main(String[] args) throws Exception { // Instantiate with a producer group name. DefaultMQProducer producer = new DefaultMQProducer(Constants.TEST_GROUP_NAME); // Launch the instance. producer.start(); for (int i = 0; i < 1000; i++) { // Create a message instance, specifying topic, tag and message body. Message msg = new Message(Constants.TEST_TOPIC_NAME, "TagA", ("Hello RocketMQ From Sentinel " + i).getBytes(RemotingHelper.DEFAULT_CHARSET) ); // Call send message to deliver message to one of brokers. SendResult sendResult = producer.send(msg); System.out.printf("%s%n", sendResult); } // Shut down once the producer instance is not longer in use. producer.shutdown(); } }
@Test public void testQueueIdBigThanQueueNum() throws Exception { int queueId = 100; sendFail = false; MessageQueue mq = new MessageQueue(topic, broker1Name, queueId); Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes()); DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr); producer.send(msg, mq, new SendCallback() { @Override public void onSuccess(SendResult sendResult) { } @Override public void onException(Throwable throwable) { sendFail = true; } }); int checkNum = 50; while (!sendFail && checkNum > 0) { checkNum--; TestUtils.waitForMoment(100); } producer.shutdown(); assertThat(sendFail).isEqualTo(true); }
@Test public void testQueueIdSmallZero() throws Exception { int queueId = -100; sendFail = true; MessageQueue mq = new MessageQueue(topic, broker1Name, queueId); Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes()); DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr); producer.send(msg, mq, new SendCallback() { @Override public void onSuccess(SendResult sendResult) { sendFail = false; } @Override public void onException(Throwable throwable) { sendFail = true; } }); int checkNum = 50; while (sendFail && checkNum > 0) { checkNum--; TestUtils.waitForMoment(100); } producer.shutdown(); assertThat(sendFail).isEqualTo(false); }