I have spring application and create KafkaConfig
@Configuration
@EnableKafka
public class KafkaConfig {
@Autowired
KafkaProperties kafkaProperties;
@Bean
public ConsumerFactory<String, TeamIdEmployeeMessage> consumerFactory() {
Map<String, Object> configProps = new HashMap<>();
configProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaProperties.getBootstrapAddress());
configProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
configProps.put("security.protocol", "SSL");
configProps.put("ssl.truststore.location", kafkaProperties.getTrustStoreLocation());
configProps.put("ssl.truststore.password", kafkaProperties.getTrustStorePassword());
configProps.put("ssl.keystore.location", kafkaProperties.getKeyStoreLocation());
configProps.put("ssl.key.password", kafkaProperties.getKeyStorePassword());
configProps.put("ssl.keystore.password", kafkaProperties.getKeyStorePassword());
configProps.put("ssl.endpoint.identification.algorithm", "");
return new DefaultKafkaConsumerFactory<>(configProps, new StringDeserializer(), new JsonDeserializer<>(TeamIdEmployeeMessage.class));
}
@Bean
public ConcurrentKafkaListenerContainerFactory<String, TeamIdEmployeeMessage> kafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, TeamIdEmployeeMessage> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory());
return factory;
}
}
Also i have KafkaListener whose doing some job.
@Component
@Slf4j
public class KafkaListener {
@Autowired
QuestionAuthorService questionAuthorService;
@Autowired
BranchFgService branchFgService;
@KafkaListener(topics = "${kafka.teamid.topic}", groupId = "OpenDialGroup", containerFactory = "kafkaListenerContainerFactory")
public void employeeListener(TeamIdEmployeeMessage message) {
log.debug("Received new message:{}", message);
//...
}
My kafka properties
allow.auto.create.topics = true
auto.commit.interval.ms = 5000
auto.offset.reset = latest
bootstrap.servers = [tvlsq-ecogw001.ru:9094, tvlsq-ecogw002.ru:9094, tvlsq-ecogw003.ru:9094]
check.crcs = true
client.dns.lookup = use_all_dns_ips
client.id = consumer-OpenDialGroup-1
client.rack =
connections.max.idle.ms = 540000
default.api.timeout.ms = 60000
enable.auto.commit = false
exclude.internal.topics = true
fetch.max.bytes = 52428800
fetch.max.wait.ms = 500
fetch.min.bytes = 1
group.id = OpenDialGroup
group.instance.id = null
heartbeat.interval.ms = 3000
interceptor.classes = []
internal.leave.group.on.close = true
internal.throw.on.fetch.stable.offset.unsupported = false
isolation.level = read_uncommitted
key.deserializer = class org.apache.kafka.common.serialization.StringDeserializer
max.partition.fetch.bytes = 1048576
max.poll.interval.ms = 300000
max.poll.records = 500
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partition.assignment.strategy = [class org.apache.kafka.clients.consumer.RangeAssignor, class org.apache.kafka.clients.consumer.CooperativeStickyAssignor]
receive.buffer.bytes = 65536
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.connect.timeout.ms = null
sasl.login.read.timeout.ms = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.login.retry.backoff.max.ms = 10000
sasl.login.retry.backoff.ms = 100
sasl.mechanism = GSSAPI
sasl.oauthbearer.clock.skew.seconds = 30
sasl.oauthbearer.expected.audience = null
sasl.oauthbearer.expected.issuer = null
sasl.oauthbearer.jwks.endpoint.refresh.ms = 3600000
sasl.oauthbearer.jwks.endpoint.retry.backoff.max.ms = 10000
sasl.oauthbearer.jwks.endpoint.retry.backoff.ms = 100
sasl.oauthbearer.jwks.endpoint.url = null
sasl.oauthbearer.scope.claim.name = scope
sasl.oauthbearer.sub.claim.name = sub
sasl.oauthbearer.token.endpoint.url = null
security.protocol = SSL
security.providers = null
send.buffer.bytes = 131072
session.timeout.ms = 45000
socket.connection.setup.timeout.max.ms = 30000
socket.connection.setup.timeout.ms = 10000
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.3]
ssl.endpoint.identification.algorithm =
ssl.engine.factory.class = null
ssl.key.password = [hidden]
ssl.keymanager.algorithm = SunX509
ssl.keystore.certificate.chain = null
ssl.keystore.key = null
ssl.keystore.location = /usr/conf/ssl/kafka_keystore.jks
ssl.keystore.password = [hidden]
ssl.keystore.type = JKS
ssl.protocol = TLSv1.3
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.certificates = null
ssl.truststore.location = /usr/conf/ssl/kafka_truststore.jks
ssl.truststore.password = [hidden]
ssl.truststore.type = JKS
value.deserializer = class org.springframework.kafka.support.serializer.JsonDeserializer
and i hav successful message about subscribe in log. Consumer initialized and subscribe to topic. Topic name is right.
15:12:40.418 11819 [ServerService Thread Pool -- 89] DEBUG org.apache.kafka.clients.consumer.KafkaConsumer - [Consumer clientId=consumer-OpenDialGroup-1, groupId=OpenDialGroup] Kafka consumer initialized
15:12:40.420 11821 [ServerService Thread Pool -- 89] INFO org.apache.kafka.clients.consumer.KafkaConsumer - [Consumer clientId=consumer-OpenDialGroup-1, groupId=OpenDialGroup] Subscribed to topic(s): OPENDIAL_EMPLOYEE
also this message spam every second/ I think its OK and mean what consumer ready to read message.
15:20:18.836 470237 [org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1] DEBUG org.apache.kafka.clients.FetchSessionHandler - [Consumer clientId=consumer-OpenDialGroup-1, groupId=OpenDialGroup] Built incremental fetch (sessionId=1170397049, epoch=906) for node 3. Added 0 partition(s), altered 0 partition(s), removed 0 partition(s), replaced 0 partition(s) out of 1 partition(s)
15:20:18.836 470237 [org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1] DEBUG org.apache.kafka.clients.consumer.internals.Fetcher - [Consumer clientId=consumer-OpenDialGroup-1, groupId=OpenDialGroup] Sending READ_UNCOMMITTED IncrementalFetchRequest(toSend=(), toForget=(), toReplace=(), implied=(TEAMID_OPENDIAL_EMPLOYEE-1), canUseTopicIds=False) to broker 10.48.70.222:9094 (id: 3 rack: null)
15:20:18.836 470237 [org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1] DEBUG org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-OpenDialGroup-1, groupId=OpenDialGroup] Sending FETCH request with header RequestHeader(apiKey=FETCH, apiVersion=12, clientId=consumer-OpenDialGroup-1, correlationId=1978) and timeout 30000 to node 3: FetchRequestData(clusterId=null, replicaId=-1, maxWaitMs=500, minBytes=1, maxBytes=52428800, isolationLevel=0, sessionId=1170397049, sessionEpoch=906, topics=[], forgottenTopicsData=[], rackId='')
15:20:18.966 470367 [kafka-coordinator-heartbeat-thread | OpenDialGroup] DEBUG org.apache.kafka.clients.consumer.internals.ConsumerCoordinator - [Consumer clientId=consumer-OpenDialGroup-1, groupId=OpenDialGroup] Sending Heartbeat request with generation 35 and member id consumer-OpenDialGroup-1-71fdb379-2f55-4947-bf65-8d2c70398b3c to coordinator 10.48.70.222:9094 (id: 2147483644 rack: null)
15:20:18.967 470368 [kafka-coordinator-heartbeat-thread | OpenDialGroup] DEBUG org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-OpenDialGroup-1, groupId=OpenDialGroup] Sending HEARTBEAT request with header RequestHeader(apiKey=HEARTBEAT, apiVersion=4, clientId=consumer-OpenDialGroup-1, correlationId=1979) and timeout 30000 to node 2147483644: HeartbeatRequestData(groupId='OpenDialGroup', generationId=35, memberId='consumer-OpenDialGroup-1-71fdb379-2f55-4947-bf65-8d2c70398b3c', groupInstanceId=null)
15:20:18.969 470370 [org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1] DEBUG org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-OpenDialGroup-1, groupId=OpenDialGroup] Received HEARTBEAT response from node 2147483644 for request with header RequestHeader(apiKey=HEARTBEAT, apiVersion=4, clientId=consumer-OpenDialGroup-1, correlationId=1979): HeartbeatResponseData(throttleTimeMs=0, errorCode=0)
15:20:18.969 470370 [org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1] DEBUG org.apache.kafka.clients.consumer.internals.ConsumerCoordinator - [Consumer clientId=consumer-OpenDialGroup-1, groupId=OpenDialGroup] Received successful Heartbeat response
But a apllication doesn poll message
I have expected my message