Java Code Examples for com.alibaba.rocketmq.client.producer.DefaultMQProducer#setNamesrvAddr()
The following examples show how to use
com.alibaba.rocketmq.client.producer.DefaultMQProducer#setNamesrvAddr() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Producer.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) throws MQClientException, InterruptedException { DefaultMQProducer producer = new DefaultMQProducer("yyzGroup2"); producer.setNamesrvAddr("10.2.223.157:9876;10.2.223.158:9876;10.2.223.159:9876"); // producer.setNamesrvAddr("10.2.223.228:9876"); producer.start(); for(int i = 0; i < 111111; ++i) { // Thread.currentThread().sleep(50); // for (String item : array) { Message msg = new Message("yyztest2",// topic "TAG",// tag "ffff",// 注意, msgkey对帮助业务排查消息投递问题很有帮助,请设置成和消息有关的业务属性,比如订单id ,商品id . "yang ya zhou".getBytes());// body //默认会设置等待消息存储成功。 SendResult sendResult = null; try {//同步发送消息 ,并且等待消息存储成功,超时时间3s . System.out.println("send msg with msgKey:" + msg.getKeys()); sendResult = producer.send(msg); //DefaultMQProducer.send } catch (Exception e) { e.printStackTrace(); } System.out.println(sendResult); Thread.sleep(300); } System.out.println(System.getProperty("user.home") ); producer.shutdown(); }
Example 2
Source File: Producer.java From zheng with MIT License | 6 votes |
public static void main(String[] args) { DefaultMQProducer producer = new DefaultMQProducer("Producer"); producer.setNamesrvAddr("127.0.0.1:9876"); try { producer.start(); long time = System.currentTimeMillis(); System.out.println("开始:" + time); int a = 100000; for (int i = 1; i <= a; i++) { Message msg = new Message("PushTopic", "push", i + "", "Just for test.".getBytes()); SendResult result = producer.send(msg); System.out.println("id:" + result.getMsgId() + " result:" + result.getSendStatus()); } System.out.println("结束,消耗:" + (System.currentTimeMillis() - time)); } catch (Exception e) { e.printStackTrace(); } finally { producer.shutdown(); } }
Example 3
Source File: RocketMQProducerService.java From onetwo with Apache License 2.0 | 6 votes |
@Override public void afterPropertiesSet() throws Exception { Assert.hasText(groupName); // Assert.hasText(namesrvAddr); DefaultMQProducer defaultMQProducer = new DefaultMQProducer(groupName); defaultMQProducer.setNamesrvAddr(namesrvAddr); defaultMQProducer.setVipChannelEnabled(false); defaultMQProducer.start(); this.defaultMQProducer = defaultMQProducer; }
Example 4
Source File: MqProducer.java From RocketMqCurrencyBoot with Apache License 2.0 | 5 votes |
@PostConstruct private void init() throws MQClientException { if (transaction == null || transactionExecuter == null) { DefaultMQProducer defaultProducer = new DefaultMQProducer(); // Producer 组名, 多个 Producer 如果属于一 个应用,发送同样的消息,则应该将它们 归为同一组 defaultProducer.setProducerGroup(ProducerGroupName); // Name Server 地址列表 defaultProducer.setNamesrvAddr(NamesrvAddr); // 生产者名称 defaultProducer.setInstanceName(InstanceName); // 超时时间 defaultProducer.setSendMsgTimeout(SendMsgTimeout); defaultProducer.start(); producer = defaultProducer; } else { TransactionMQProducer transactionProducer = new TransactionMQProducer(); // Producer 组名, 多个 Producer 如果属于一 个应用,发送同样的消息,则应该将它们 归为同一组 transactionProducer.setProducerGroup(ProducerGroupName); // Name Server 地址列表 transactionProducer.setNamesrvAddr(NamesrvAddr); // 生产者名称 transactionProducer.setInstanceName(InstanceName); // 超时时间 transactionProducer.setSendMsgTimeout(SendMsgTimeout); transactionProducer.setCheckThreadPoolMinSize(checkThreadPoolMinSize); transactionProducer.setCheckThreadPoolMaxSize(checkThreadPoolMaxSize); transactionProducer.setCheckRequestHoldMax(checkRequestHoldMax); transactionProducer.setTransactionCheckListener(transaction); transactionProducer.start(); producer = transactionProducer; } }
Example 5
Source File: RocketMqTracingCollector.java From dubbo-plus with Apache License 2.0 | 5 votes |
public RocketMqTracingCollector() { defaultMQProducer = new DefaultMQProducer(DstConstants.ROCKET_MQ_PRODUCER); defaultMQProducer.setNamesrvAddr(ConfigUtils.getProperty(DstConstants.ROCKET_MQ_NAME_SRV_ADD)); try { defaultMQProducer.start(); } catch (MQClientException e) { throw new IllegalArgumentException("fail to start rocketmq producer.",e); } }
Example 6
Source File: RocketMQProducer.java From uavstack with Apache License 2.0 | 4 votes |
private DefaultMQProducer initProducer(String producerGroup, String nameServer) { DefaultMQProducer dmp = new DefaultMQProducer(producerGroup); dmp.setNamesrvAddr(nameServer); return dmp; }