HTTP Bridge
Last updated
Last updated
Stop all server in previous lab
type ctrl+c in each terminal (stop kafka before stop zookeeper)
check kafka broker and zookeeper process with jps command
clear old data in previous lab
start zookeeper
start kafka broker
The Kafka Bridge provides a RESTful interface that allows HTTP-based clients to interact with a Kafka cluster. It offers the advantages of a web API connection to AMQ Streams, without the need for client applications to interpret the Kafka protocol.
The API has two main resources — consumers and topics — that are exposed and made accessible through endpoints to interact with consumers and producers in your Kafka cluster. The resources relate only to the Kafka Bridge, not the consumers and producers connected directly to Kafka.
layout of kafka http bridge after extract from zip file
You configure the Kafka Bridge, as any other Kafka client, using appropriate prefixes for Kafka-related properties.
"kafka." for general configuration that applies to producers and consumers, such as server connection and security.
"kafka.consumer." for consumer-specific configuration passed only to the consumer.
"kafka.producer." for producer-specific configuration passed only to the producer.
Configure HTTP-related properties to enable HTTP access to the Kafka cluster.
Run the Kafka Bridge script using the configuration properties as a parameter:
example result
create "bridge-quickstart-topic" topic
Verifying the topic was created
Using the Kafka Bridge, produce messages to the topic you created:
If the request is successful, the Kafka Bridge returns an offsets array, along with a 200 code and a content-type header of application/vnd.kafka.v2+json. For each message, the offsets array describes:
The partition that the message was sent to
The current message offset of the partition
Example response
List Topics
example result
Get topic configuration and partition details
example response
try to test with another function
List the partitions of a specific topic
List the details of a specific topic partition
List the offsets of a specific topic partition
Create a Kafka Bridge consumer in a new consumer group named bridge-quickstart-consumer-group:
The consumer is named bridge-quickstart-consumer and the embedded data format is set as json.
Some basic configuration settings are defined.
The consumer will not commit offsets to the log automatically because the enable.auto.commit setting is false. You will commit the offsets manually later in this quickstart.
If the request is successful, the Kafka Bridge returns the consumer ID (instance_id) and base URL (base_uri) in the response body, along with a 200 code.
example response
Copy the base URL (base_uri) to use in the other consumer operations in this quickstart.
Subscribe the consumer to the bridge-quickstart-topic topic that you created earlier (If the request is successful, the Kafka Bridge returns a 204 (No Content) code only.):
Retrieve the latest messages from the Kafka Bridge consumer by requesting data from the records endpoint. In production, HTTP clients can call this endpoint repeatedly (in a loop).
Submit a GET request to the records endpoint:
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 previous step 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. (repeat call until have response from bridge)
example result
Download from Red Hat Web Site and Extract to your path
example of