// Module included in the following assemblies:
//
// assembly-kafka-bridge-quickstart.adoc

[id='proc-bridge-retrieving-latest-messages-from-consumer-{context}']
= Retrieving the latest messages from a Kafka Bridge consumer

[role="_abstract"]
Retrieve the latest messages from the Kafka Bridge consumer by requesting data from the xref:poll[records] endpoint. In production, HTTP clients can call this endpoint repeatedly (in a loop).

.Procedure

.  Produce additional messages to the Kafka Bridge consumer, as described in xref:proc-producing-messages-from-bridge-topics-partitions-{context}[Producing messages to topics and partitions].

. Submit a `GET` request to the `records` endpoint:
+
[source,curl,subs=attributes+]
----
curl -X GET http://localhost:8080/consumers/bridge-quickstart-consumer-group/instances/bridge-quickstart-consumer/records \
  -H 'accept: application/vnd.kafka.json.v2+json'
----
+
After creating and subscribing to a Kafka Bridge consumer, a first GET request will return an empty response because the poll operation starts a rebalancing process to assign partitions.

. Repeat step two to retrieve messages from the Kafka Bridge consumer.
+
The Kafka Bridge returns an array of messages -- describing the topic name, key, value, partition, and offset -- in the response body, along with a `200` code. Messages are retrieved from the latest offset by default.
+
[source,json,subs=attributes+]
----
HTTP/1.1 200 OK
content-type: application/vnd.kafka.json.v2+json
#...
[
  {
    "topic":"bridge-quickstart-topic",
    "key":"my-key",
    "value":"sales-lead-0001",
    "partition":0,
    "offset":0
  },
  {
    "topic":"bridge-quickstart-topic",
    "key":null,
    "value":"sales-lead-0003",
    "partition":0,
    "offset":1
  },
#...
----
+
NOTE: If an empty response is returned, produce more records to the consumer as described in xref:proc-producing-messages-from-bridge-topics-partitions-{context}[Producing messages to topics and partitions], and then try retrieving messages again.

.What to do next

After retrieving messages from a Kafka Bridge consumer, try xref:proc-bridge-committing-consumer-offsets-to-log-{context}[committing offsets to the log].

[role="_additional-resources"]
.Additional resources

* xref:poll[GET /consumers/{groupid}/instances/{name}/records]
