zcsh0721 commented on issue #2730:
URL: https://github.com/apache/rocketmq/issues/2730#issuecomment-809166480


   @if
    `ConcurrentMap<String, TopicRouteData> table = 
producer.getDefaultMQProducerImpl().getmQClientFactory().getTopicRouteTable();` 
   这样可以吧 , 而且 我也发送消息了
   完整测试代码 
   ```
       public static void main(String[] args) throws InterruptedException, 
MQClientException {
   
   
           DefaultMQProducer producer = new 
DefaultMQProducer("please_rename_unique_group_name");
           producer.setNamesrvAddr("127.0.0.1:9876");
   
           for (int i = 0; i < 1000; i++) {
               try {
                   Message msg = new Message("TopicTest" /* Topic */,
                       "TagA" /* Tag */,
                       ("Hello RocketMQ " + 
i).getBytes(RemotingHelper.DEFAULT_CHARSET) /* Message body */
                   );
                   SendResult sendResult = producer.send(msg);
               } catch (Exception e) {
                   e.printStackTrace();
                   Thread.sleep(1000);
               }
           }
   
   //        producer.shutdown();
   
           ConcurrentMap<String, TopicRouteData> table = 
producer.getDefaultMQProducerImpl().getmQClientFactory().getTopicRouteTable();
           System.out.println(table);
           Thread.sleep(10000L);
           
System.out.println("*************************************************************");
           
           DefaultMQPushConsumer consumer = new 
DefaultMQPushConsumer("please_rename_unique_group_name_4");
           consumer.setNamesrvAddr("127.0.0.1:9876");
           
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
           consumer.subscribe("TopicTest", "*");
           consumer.registerMessageListener(new MessageListenerConcurrently() {
   
               @Override
               public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> 
msgs,
                   ConsumeConcurrentlyContext context) {
                   System.out.printf("%s Receive New Messages: %s %n", 
Thread.currentThread().getName(), msgs);
                   return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
               }
           });
           consumer.start();
   
           System.out.printf("Consumer Started.%n");
       }
   ```
    
    我把 `ClientConfig.changeInstanceNameToPID()`改为如下
   ```
       public void changeInstanceNameToPID() {
           if (this.instanceName.equals("DEFAULT")) {
               this.instanceName = UtilAll.getPid() +"";
               System.out.println("instanceName=" + instanceName);
           }
       }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to