We are using spring-cloud-stream-binder-kafka-streams dependency in the project. The service is communicating with other services using Kafka, these are listeners set up in application.yaml
:
spring:
cloud:
kafka:
stream:
bindings:
listenToBookTopic-in-0:
consumer:
applicationId: someAppId
listenToUserTopic-in-0:
consumer:
applicationId: someAppId2
materializedAs: user-store
listenToRolesTopic-in-0:
consumer:
applicationId: someAppId3
materializedAs: role-store
Among others there is a Kafka listener for the Book objects:
@Bean
public Function<KStream<String, OldBook>, KStream<String, NewBook>> listenToTopic() {
return stream -> stream
.map((key, oldBook) -> {
try {
final var newBook = bookService.processBook(oldBook);
final String newKey = createNewKey(newBook);
return KeyValue.pair(newKey, newBook);
} catch (Exception e) {
log.error(e.getMessage());
return KeyValue.pair("", null);
}
});
}
Book Service:
@Autowired
private final StateStoreService stateStoreService;
public NewBook processBook(OldBook oldBook) {
final var newBook = createBook(oldBook);
newBook.setUser(stateStoreService.getUserById(oldBook.getId());
newBook.setRoles(stateStoreService.getRolesById(oldBook.getId());
return newBook;
}
StateStoreService:
@Autowired
private final InteractiveQueryService indicativeQueryService;
public Optional<User> getUserById(final String id) {
final ReadOnlyKeyValueStore<String, User> userStore = interactiveQueryService.getQueryableStore(
properties.getUserStore(), QueryableStoreTypes.keyValueStore());
return Optional.ofNullable(userStore.get(brid));
}
public Optional<Role> getRoleById(final String id) {
final ReadOnlyKeyValueStore<String, Role> store = interactiveQueryService
.getQueryableStore(properties.getRoleStore(), QueryableStoreTypes.keyValueStore());
return Optional.ofNullable(store.get(id));
}
So, what happens is:
when the StateStoreService.getUserById()
is called from the normal request scope, then InteractiveQueryService.getQueryableStore()
throws no WARNs. When the same methods of StateStoreService
are invoked from the listenToBookTopic
bean, the WARN containing following is produced:
"Store storeName could not be found in Streams context, falling back to all known Streams instances"
According to my investigations, when getUserById()
is invoked from the listenToBookTopic bean, some contextSpecificKafkaStreams are found at the line
KafkaStreams contextSpecificKafkaStreams = getThreadContextSpecificKafkaStreams();
This leads to the check if the contextSpecificKafkaStreams contains required StateStore. Obviously it doesnt, so Spring falls back to looking into all other available KafkaStreams. I assume that the reason for such context-specific StateStores being created are materialized views assigned to the specific listener running on the separate thread with specific name, by which its distinguished if the StateStore is context-specific for this given thread.
Actual problem is that the WARN is produced for each Book received. I was searching for some possible solutions, but have found nothing relevant. Is it possible to get rid of this warning in some clean and gentle way?