安装RocketMQ及配置测试

安装

wget https://github.com/alibaba/RocketMQ/releases/download/v3.2.6/alibaba-rocketmq-3.2.6.tar.gz
tar alibaba-rocketmq-3.2.6.tar.gz
cd  alibaba-rocketmq


启动

nohup sh mqnamesrv -n 10.105.23.114:9876 & 
nohup sh mqbroker -n 10.105.23.114:9876


java测试

使用maven构建环境
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <!-- http://mvnrepository.com/artifact/com.alibaba.rocketmq/rocketmq-client -->  
  2. <dependency>  
  3.     <groupId>com.alibaba.rocketmq</groupId>  
  4.     <artifactId>rocketmq-client</artifactId>  
  5.     <version>3.2.3</version>  
  6. </dependency>  
[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. package rocketmq;  
  2.   
  3.   
  4. import java.util.Date;  
  5.   
  6.   
  7. import com.alibaba.rocketmq.client.exception.MQClientException;  
  8. import com.alibaba.rocketmq.client.producer.DefaultMQProducer;  
  9. import com.alibaba.rocketmq.client.producer.SendResult;  
  10. import com.alibaba.rocketmq.common.message.Message;  
  11.   
  12.   
  13. public class Producer {  
  14.     public static void main(String[] args) throws MQClientException, InterruptedException {  
  15.         DefaultMQProducer producer = new DefaultMQProducer("rmq-group");  
  16.         producer.setNamesrvAddr("182.254.145.66:9876");  
  17.         producer.setInstanceName("rmq-instance");  
  18.         producer.start();  
  19.         try {  
  20.             for (int i = 0; i < 3; i++) {  
  21.                 Message msg = new Message("TopicA-test",// topic  
  22.                     "TagA",// tag  
  23.                         (new Date() + "Hello RocketMQ ,QuickStart" + i)  
  24.                                 .getBytes()// body  
  25.                 );  
  26.                 SendResult sendResult = producer.send(msg);  
  27.             }  
  28.         } catch (Exception e) {  
  29.             e.printStackTrace();  
  30.         }  
  31.         producer.shutdown();  
  32.     }  
  33. }  
  34.   
  35.   
  36.   
  37.   
  38. package rocketmq;  
  39.   
  40.   
  41. import java.util.List;  
  42.   
  43.   
  44. import com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer;  
  45. import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;  
  46. import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;  
  47. import com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently;  
  48. import com.alibaba.rocketmq.client.exception.MQClientException;  
  49. import com.alibaba.rocketmq.common.message.MessageExt;  
  50.   
  51.   
  52. public class Consumer {  
  53.    
  54.     public static void main(String[] args) throws InterruptedException, MQClientException {  
  55.         DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("rmq-group");  
  56.    
  57.         consumer.setNamesrvAddr("182.254.145.66:9876");  
  58.         consumer.setInstanceName("rmq-instance");  
  59.         consumer.subscribe("TopicA-test""TagA");  
  60.    
  61.         consumer.registerMessageListener(new MessageListenerConcurrently() {  
  62.             @Override  
  63.             public ConsumeConcurrentlyStatus consumeMessage(  
  64.                     List<MessageExt> msgs, ConsumeConcurrentlyContext context) {  
  65.                 for (MessageExt msg : msgs) {  
  66.                     System.out.println(new String(msg.getBody()));  
  67.                 }  
  68.                 return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;  
  69.             }  
  70.         });  
  71.         consumer.start();  
  72.         System.out.println("Consumer Started.");  
  73.     }  
  74. }  

运行consumer后发现
com.alibaba.rocketmq.remoting.exception.RemotingConnectException: connect to <10.105.23.114:10911> failed
在nohup.out里发现 
The broker[localhost, 10.105.23.114:10911] boot success. and name server is 182.254.145.65:9876
哎,看来还是外网内网ip的问题

上次在安装Tair的时候就碰到过类似的问题 详见  Centos7安装Tair及配置测试


最后经过多方搜索,在官方的用户说明里看到下面的方法

经过我修改后的broker.p
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. namesrvAddr=127.0.0.1:9876  
  2. brokerIP1=182.254.145.66  
  3. brokerName=localhost  
  4. brokerClusterName=DefaultCluster  
  5. brokerId=0  
  6. autoCreateTopicEnable=true  
  7. autoCreateSubscriptionGroup=true  
  8. rejectTransactionMessage=false  
  9. fetchNamesrvAddrByAddressServer=false  
  10. storePathRootDir=/root/store  
  11. storePathCommitLog=/root/store/commitlog  
  12. flushIntervalCommitLog=1000  
  13. flushCommitLogTimed=false  
  14. deleteWhen=04  
  15. fileReservedTime=72  
  16. maxTransferBytesOnMessageInMemory=262144  
  17. maxTransferCountOnMessageInMemory=32  
  18. maxTransferBytesOnMessageInDisk=65536  
  19. maxTransferCountOnMessageInDisk=8  
  20. accessMessageInMemoryMaxRatio=40  
  21. messageIndexEnable=true  
  22. messageIndexSafe=false  
  23. haMasterAddress=  
  24. brokerRole=ASYNC_MASTER  
  25. flushDiskType=ASYNC_FLUSH  
  26. cleanFileForciblyEnable=true  


ok!
这说明什么?说明第一手资料很重要




参考资料

http://www.jialeens.com/archives/681.html
http://www.cnblogs.com/xiaodf/p/5075167.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值