Spring Kafka Consumer在Tomcat中部署时不起作用

时间:2018-09-07 17:43:25

标签: spring-boot spring-kafka

我有一个春季的kafka使用者,可以从一个主题读取消息并写入另一个主题。我正在使用Spring Kafka 2.1.8。当此应用程序作为Spring Boot运行时,它工作正常。当作为战争部署到外部tomcat服务器(在我的工作站上尝试过的关键性tc服务器以及外部tomcat服务器)时,消费者读取一条消息,发送给下游主题,并且卡住。我所看到的只是发送给协调员的心跳消息。当作为Spring Boot运行时,消息的代码完全相同,处理过程为100。我不确定这是否与spring kafka或我对spring boot的无知有关。

@Bean
      public Map<String, Object> consumerConfigs() {
        Map<String, Object> consumerProperties = new HashMap<>();
        consumerProperties.put("bootstrap.servers", kafkaConfigService.getKAFKA_BOOTSTRAP_SERVERS());
        consumerProperties.put("client.id", "rawlogs_client");
        consumerProperties.put("group.id", "rawlogs_etl");
        consumerProperties.put("enable.auto.commit", "false");
        consumerProperties.put("session.timeout.ms", "30000");
        consumerProperties.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        consumerProperties.put("value.deserializer", "io.confluent.kafka.serializers.KafkaAvroDeserializer");
        consumerProperties.put("schema.registry.url", kafkaConfigService.getKAFKA_SCHEMA_REGISTRY_URL());
        consumerProperties.put("isolation.level", "read_committed");
        consumerProperties.put(KafkaAvroDeserializerConfig.SPECIFIC_AVRO_READER_CONFIG, true);
        consumerProperties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
        consumerProperties.put("max.poll.records", "100");
        return consumerProperties;
      }
         @Bean
      public ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(
          ConsumerFactory<String, SpecificRecord> kafkaConsumerFactory
         ) {
        ConcurrentKafkaListenerContainerFactory<String, SpecificRecord> factory = new ConcurrentKafkaListenerContainerFactory<>();
        factory.setConsumerFactory(consumerFactory());
        factory.getContainerProperties().setTransactionManager(kafkaTransactionManager());
        factory.getContainerProperties().setAckMode(AckMode.BATCH);
        factory.getContainerProperties().setIdleEventInterval(60000L);
        factory.getContainerProperties().setAckOnError(false);
        factory.setRetryTemplate(getRetryTemplate());
        factory.getContainerProperties().setConsumerTaskExecutor(threadPoolExecutor());
        return factory;
      }



               @Bean
              public RetryTemplate getRetryTemplate() {
                  RetryTemplate retryTemplate = new RetryTemplate();
                  FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
                  backOffPolicy.setBackOffPeriod(1000);
                  RetryPolicy retryPolicy = new SimpleRetryPolicy();
                  retryTemplate.setBackOffPolicy(backOffPolicy);
                  retryTemplate.setRetryPolicy(retryPolicy);
                  retryTemplate.registerListener(retryListener());
                  return retryTemplate;
              }
    @Bean
     public  ThreadPoolTaskExecutor threadPoolExecutor() {
             ThreadPoolTaskExecutor executor= new ThreadPoolTaskExecutor();
             executor.setMaxPoolSize(3);
             executor.initialize();
             return executor;
         }

0 个答案:

没有答案