Liveness probe for RabbitMQ Client (Consumer)

11/19/2018

I would like to know/get opinions on how to setup liveness probe for a RabbitMQ queue consumer. I am not sure how to verify if consumer is still processing messages from the queue. I have already tried searching for some clues over the internet but could not find any. So just asking a question here to see if anyone has got any idea.

The code block which I want to make sure working fine is

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var body = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    Console.WriteLine(
quot;Message Received: {message}")
; };

Thank you.

-- Alpesh
azure-aks
c#
kubernetes
rabbitmq

1 Answer

11/19/2018

First thing, you will need to expose an HTTP endpoint in your application code that checks whether the consumer is alive or not.

There are many ways to test the liveness of the consumer, for example, you can check the timestamp of the last message that was consumed. If it's too old, you could declare the consumer as dead by returning an HTTP 500 error, otherwise, return HTTP 200. It depends on your business logic, you might want to use what I proposed, or any other method that fits your needs.

Once you have an HTTP endpoint, you can define a liveness probe in your Kubernetes manifest.

livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
        httpHeaders:
        - name: X-Custom-Header
          value: Awesome
      initialDelaySeconds: 3
      periodSeconds: 3

(Taken from https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/)

-- areller
Source: StackOverflow