I am currently trying to implement access to a Kafka topic via a REST API endpoint on my Quarkus application, in order not to give my clients direct access to the broker.
However, I have the need to consume all the events of the topic from offset 0, since a client might loose connection to my endpoint and therefore miss some events, which is not desirable.
I have tried to follow the official Quarkus guide on Kafka, and my endpoint currently looks like this:
@Path("poll-path")
public class PollService {
@Inject
@Channel("my-channel")
Multi<MyEvent> myEventStream;
@GET
@RestStreamElementType(MediaType.APPLICATION_JSON)
public Multi<MyEvent> consumerEndpoint() {
// Filter events relevant to the authenticated client from the stream...
return myEventStream;
}
My application.properties are configured as follows:
mp.messaging.incoming.my-channel.connector=smallrye-kafka
mp.messaging.incoming.my-channel.topic=my-topic
mp.messaging.incoming.my-channel.commit-strategy=ignore
Testing my endpoint with Postman, I currently receive all events from offset 0 only for the first connection I establish after my application startup.
I suppose that the Quarkus application is probably seen as the one and only consumer of the topic by Kafka, so that the offset is actually 0 only when the first connection between the application and the broker is established.
Basing on that assumption, I tried to find a way to create a new consumer for that Kafka topic every time a client connects to my endpoint, so that they will actually be capable of retrieving all events from the beginning, but I have not find any solution.
Has anyone faced a similar problem before and found a way out?
chrypt0s is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.