Skip to content

Try Locally

gaurav-ashok edited this page Dec 11, 2024 · 2 revisions

Setting up varadhi locally

Requirement

Make sure you have docker, java 21 and python installed.

Clone the repo and build

git clone https://github.com/flipkart-incubator/varadhi.git
cd varadhi
./gradlew build copyDependencies copyConfigForE2E -x test
docker build . --file setup/docker/Dockerfile --tag varadhi.docker.registry/varadhi:latest

Lets run the varadhi application along with its dependencies via docker compose

docker compose --profile service --profile dev-metric -f setup/docker/compose.yml up -d --wait --wait-timeout 180

# a simple http server acting as a destination app
python3 -c "from http.server import HTTPServer, BaseHTTPRequestHandler; HTTPServer(('0.0.0.0', 8000), type('', (BaseHTTPRequestHandler,), {'do_POST': lambda self: (self.send_response(200), self.end_headers(), print('Headers:', self.headers), print('Body:', self.rfile.read(int(self.headers.get('Content-Length'))).decode('utf-8')))})).serve_forever()" &

Lets create the entities and produce messages to a topic

./setup/create_entities.sh default_org team default_project default_topic

Produce the message

curl --request POST \
  --url http://localhost:18488/v1/projects/default_project/topics/default_topic/produce \
  --header 'x_user_id: thanos' \
  --header 'x_restbus_message_id: aa-bb-cc-dd' \
  --data '{
	"hello": "world"
}'

You should now see the output from python server like following:

10.5.5.2 - - [11/Dec/2024 20:03:59] "POST /messages HTTP/1.1" 200 -
Content-Length: 21
Host: host.docker.internal:8000
User-Agent: Java-http-client/21.0.5
Content-Type: application/json
x_restbus_message_id: aa-bb-cc-dd
x_restbus_produce_identity: thanos
x_restbus_produce_region: default
x_restbus_produce_timestamp: 1733927639019
x_user_id: thanos
Body: {
	"hello": "world"
}

So, what just happened? We made the produce call to varadhi. Varadhi persisted the message and tried to deliver the same message to the endpoint that is configured in the subscription. On delivery, the python server printed the same message.

Teardown

# stop the docker containers
docker compose --profile service --profile dev-metric -f setup/docker/compose.yml down --volumes

# find the pid listening on port 8000 and kill it
lsof -i :8000 | grep python3 | awk '{print $2}' | xargs kill