zhanghui95 commented on issue #398:
URL: 
https://github.com/apache/rocketmq-clients/issues/398#issuecomment-1471605681

   > ```java
   > final ClientServiceProvider provider = ClientServiceProvider.loadService();
   > 
   > // Credential provider is optional for client configuration.
   > String accessKey = "yourAccessKey";
   > String secretKey = "yourSecretKey";
   > SessionCredentialsProvider sessionCredentialsProvider =
   >     new StaticSessionCredentialsProvider(accessKey, secretKey);
   > 
   > String endpoints = "foobar:8080";
   > ClientConfiguration clientConfiguration = ClientConfiguration.newBuilder()
   >     .setEndpoints(endpoints)
   >     .setCredentialProvider(sessionCredentialsProvider)
   >     .build();
   > String topic = "yourTopic";
   > // In most case, you don't need to create too many producers, singleton 
pattern is recommended.
   > final Producer producer = provider.newProducerBuilder()
   >     .setClientConfiguration(clientConfiguration)
   >     // Set the topic name(s), which is optional but recommended. It makes 
producer could prefetch the topic
   >     // route before message publishing.
   >     .setTopics(topic)
   >     // May throw {@link ClientException} if the producer is not 
initialized.
   >     .build();
   > // Define your message body.
   > byte[] body = "This is a normal message for Apache 
RocketMQ".getBytes(StandardCharsets.UTF_8);
   > String tag = "yourMessageTagA";
   > final Message message = provider.newMessageBuilder()
   >     // Set topic for the current message.
   >     .setTopic(topic)
   >     // Message secondary classifier of message besides topic.
   >     .setTag(tag)
   >     // Key(s) of the message, another way to mark message besides message 
id.
   >     .setKeys("yourMessageKey-0e094a5f9d85")
   >     .setBody(body)
   >     .build();
   > // Set individual thread pool for send callback.
   > ExecutorService sendCallbackExecutor = new 
ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(),
   >     Runtime.getRuntime().availableProcessors(), 60, TimeUnit.SECONDS, new 
LinkedBlockingQueue<>());
   > Stopwatch stopwatch = Stopwatch.createStarted();
   > for (int i = 0; i < 10000; i++) {
   >     final CompletableFuture<SendReceipt> future = 
producer.sendAsync(message);
   >     future.whenCompleteAsync((sendReceipt, throwable) -> {
   >         if (null != throwable) {
   >             log.error("Failed to send message", throwable);
   >         }
   >     }, sendCallbackExecutor);
   > }
   > log.info("cost {} ms", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
   > // Block to avoid exist of background threads.
   > Thread.sleep(Long.MAX_VALUE);
   > // Close the producer when you don't need it anymore.
   > producer.close();
   > ```
   > 
   > 这是一个可供参考的测试代码。
   
   七到十来秒不等,与旧版本每次不超过五百毫秒相差不少


-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to