You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/06/26 05:58:28 UTC

[GitHub] [pulsar] AcrazyDog edited a comment on issue #7317: too many pulsar-time-io threads

AcrazyDog edited a comment on issue #7317:
URL: https://github.com/apache/pulsar/issues/7317#issuecomment-649987785


   > @AcrazyDog Can you share the code of how you build the pulsar client?
   Thanks for you reply.
   
   first,I build a PulsarClient Bean by Spring like this:
   
   ```java
       @Bean
       public PulsarClient getPulsarClient() throws PulsarClientException {
           return PulsarClient.builder()
                   .serviceUrl(pulsar_service_url)
                   .build();
   ```
   
   and then I use it :
   ```java
       @Autowired
       private PulsarClient pulsarClient;
   
       public MessageId send(Object object, String topic) {
           return this.send(object, "key", topic);
       }
   
       public MessageId send(Object object, String key, String topic) {
           try (Producer producer = getProducer(pulsarClient, topic)) {
               String message = JSONObject.toJSONString(object, SerializerFeature.WriteMapNullValue);
               MessageId messageId = producer.newMessage().eventTime(System.currentTimeMillis()).key(key)
                       .value(message.getBytes()).send();
               log.info("send to pulsar topic :{} message :{} ",topic,message);
               return messageId;
           } catch (PulsarClientException e) {
               log.error("send pulsar message error:", e);
               throw new RuntimeException(e);
           }
       }
   
       private Producer getProducer(PulsarClient client, String topic) throws PulsarClientException {
           return client.newProducer()
                   .topic(topic)
                   .create();
       }
   ```
   


----------------------------------------------------------------
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:
users@infra.apache.org