protected void prepare() { Validate.notEmpty(options.properties, "Producer properties can not be empty"); Validate.notNull(options.selector, "TopicSelector can not be null"); Validate.notNull(options.mapper, "TupleToMessageMapper can not be null"); producer = new DefaultMQProducer(); producer.setInstanceName(UUID.randomUUID().toString()); RocketMqConfig.buildProducerConfigs(options.properties, producer); try { producer.start(); } catch (MQClientException e) { throw new RuntimeException(e); } }
public void start(String nameSrvAddr) throws MQClientException { if (isStarted.compareAndSet(false, true)) { traceProducer.setNamesrvAddr(nameSrvAddr); traceProducer.setInstanceName(TRACE_INSTANCE_NAME + "_" + nameSrvAddr); traceProducer.start(); } this.worker = new Thread(new AsyncRunnable(), "MQ-AsyncTraceDispatcher-Thread-" + dispatcherId); this.worker.setDaemon(true); this.worker.start(); this.registerShutDownHook(); }
@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(); } } }
@Override public void prepare(Map<String, Object> topoConf, TopologyContext context, OutputCollector collector) { Validate.notEmpty(properties, "Producer properties can not be empty"); Validate.notNull(selector, "TopicSelector can not be null"); Validate.notNull(mapper, "TupleToMessageMapper can not be null"); producer = new DefaultMQProducer(); producer.setInstanceName(String.valueOf(context.getThisTaskId())); RocketMqConfig.buildProducerConfigs(properties, producer); try { producer.start(); } catch (MQClientException e) { throw new RuntimeException(e); } this.collector = collector; this.batchHelper = new BatchHelper(batchSize, collector); this.messages = new LinkedList<>(); }
/** * Starts the producer. * * @throws MQClientException */ public void start() throws MQClientException { producer = new DefaultMQProducer(PRODUCER_GROUP_NAME); producer.setInstanceName("producer-" + System.currentTimeMillis()); producer.setNamesrvAddr(namesrvAddr); producer.start(); }
defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); DefaultMQProducer defaultMQProducer = new DefaultMQProducer("ReSendMsgById"); defaultMQProducer.setInstanceName(Long.toString(System.currentTimeMillis()));
producer.setInstanceName(Long.toString(System.currentTimeMillis()));
private void create() { producer = new DefaultMQProducer(); producer.setProducerGroup(RandomUtil.getStringByUUID()); producer.setInstanceName(RandomUtil.getStringByUUID()); if (nsAddr != null) { producer.setNamesrvAddr(nsAddr); } }
protected void create(boolean useTLS) { producer = new DefaultMQProducer(); producer.setProducerGroup(getProducerGroupName()); producer.setInstanceName(getProducerInstanceName()); producer.setUseTLS(useTLS); if (nsAddr != null) { producer.setNamesrvAddr(nsAddr); } }
AbstractOMSProducer(final KeyValue properties) { this.properties = properties; this.rocketmqProducer = new DefaultMQProducer(); 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.rocketmqProducer.setNamesrvAddr(accessPoints.replace(',', ';')); } this.rocketmqProducer.setProducerGroup(clientConfig.getRmqProducerGroup()); String producerId = buildInstanceName(); this.rocketmqProducer.setSendMsgTimeout(clientConfig.getOperationTimeout()); this.rocketmqProducer.setInstanceName(producerId); this.rocketmqProducer.setMaxMessageSize(1024 * 1024 * 4); this.rocketmqProducer.setLanguage(LanguageCode.OMS); properties.put(OMSBuiltinKeys.PRODUCER_ID, producerId); }
public JmsBaseMessageProducer(Destination destination, CommonContext context) throws JMSException { synchronized (LOCK_OBJECT) { checkArgs(destination, context); if (null == producerMap.get(this.context.getProducerId())) { DefaultMQProducer producer = new DefaultMQProducer(context.getProducerId()); if (!Strings.isNullOrEmpty(context.getNameServer())) { producer.setNamesrvAddr(context.getNameServer()); } if (!Strings.isNullOrEmpty(context.getInstanceName())) { producer.setInstanceName(context.getInstanceName()); } if (context.getSendMsgTimeoutMillis() > 0) { producer.setSendMsgTimeout(context.getSendMsgTimeoutMillis()); } try { producer.start(); } catch (MQClientException mqe) { throw ExceptionUtil.convertToJmsException(mqe, String.format("Start producer failed:%s", context.getProducerId())); } producerMap.putIfAbsent(this.context.getProducerId(), producer); } } }
@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 { CommandLine commandLine = buildCommandline(args); if (commandLine != null) { String group = commandLine.getOptionValue('g'); String topic = commandLine.getOptionValue('t'); String tags = commandLine.getOptionValue('a'); String keys = commandLine.getOptionValue('k'); String msgCount = commandLine.getOptionValue('c'); DefaultMQProducer producer = new DefaultMQProducer(group); producer.setInstanceName(Long.toString(System.currentTimeMillis())); producer.start(); for (int i = 0; i < Integer.parseInt(msgCount); i++) { try { Message msg = new Message( topic, tags, keys, ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET)); SendResult sendResult = producer.send(msg); System.out.printf("%-8d %s%n", i, sendResult); } catch (Exception e) { e.printStackTrace(); Thread.sleep(1000); } } producer.shutdown(); } }
defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); DefaultMQProducer defaultMQProducer = new DefaultMQProducer("ReSendMsgById"); defaultMQProducer.setInstanceName(Long.toString(System.currentTimeMillis()));
@Override public void afterPropertiesSet() throws Exception { producer = new DefaultMQProducer(producerGroup); producer.setInstanceName(instanceName); producer.setNamesrvAddr(namesrvAddr); producer.setDefaultTopicQueueNums(defaultTopicQueueNums); producer.setSendMsgTimeout(sendMsgTimeout); producer.setRetryTimesWhenSendFailed(retryTimesWhenSendFailed); producer.start(); log.info("Producer Group {} started!", producerGroup); }
producer.setInstanceName(Long.toString(System.currentTimeMillis()));
private void create() { producer = new DefaultMQProducer(); producer.setProducerGroup(RandomUtil.getStringByUUID()); producer.setInstanceName(RandomUtil.getStringByUUID()); if (nsAddr != null) { producer.setNamesrvAddr(nsAddr); } }
protected void create(boolean useTLS) { producer = new DefaultMQProducer(); producer.setProducerGroup(getProducerGroupName()); producer.setInstanceName(getProducerInstanceName()); producer.setUseTLS(useTLS); if (nsAddr != null) { producer.setNamesrvAddr(nsAddr); } }
AbstractOMSProducer(final KeyValue properties) { this.properties = properties; this.rocketmqProducer = new DefaultMQProducer(); 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.rocketmqProducer.setNamesrvAddr(accessPoints.replace(',', ';')); this.rocketmqProducer.setProducerGroup(clientConfig.getRmqProducerGroup()); String producerId = buildInstanceName(); this.rocketmqProducer.setSendMsgTimeout(clientConfig.getOmsOperationTimeout()); this.rocketmqProducer.setInstanceName(producerId); this.rocketmqProducer.setMaxMessageSize(1024 * 1024 * 4); properties.put(PropertyKeys.PRODUCER_ID, producerId); }
public void start(String nameSrvAddr) throws MQClientException { if (isStarted.compareAndSet(false, true)) { traceProducer.setNamesrvAddr(nameSrvAddr); traceProducer.setInstanceName(TRACE_INSTANCE_NAME + "_" + nameSrvAddr); traceProducer.start(); } this.worker = new Thread(new AsyncRunnable(), "MQ-AsyncTraceDispatcher-Thread-" + dispatcherId); this.worker.setDaemon(true); this.worker.start(); this.registerShutDownHook(); }