Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to automatically restart KrakenD when rabbitMQ connection is not available? #486

Closed
shi-rudo opened this issue Apr 27, 2022 · 3 comments · Fixed by #697
Closed

How to automatically restart KrakenD when rabbitMQ connection is not available? #486

shi-rudo opened this issue Apr 27, 2022 · 3 comments · Fixed by #697

Comments

@shi-rudo
Copy link

I have the problem when I start krakend before my rabbitMQ server that I have to restart the server krakend server to establish a connection.

The Krachend server is ready before the startup process of the rabbit is completed. Or also if the Krakend server was started before the RabbitMq server. Unfortunately, I could not find anything in the documentation how to solve the problem. Is there any war to automatically trigger a krakend reboot or exit when the connection fails?

Running on docker compose:

Steps:
01: Starting RabbitMQ
02: Starting krakend
03: Calling krakend endpoint
--> ❌ KRAKEND ERROR: [ENDPOINT: /api/user/register-user/:key] Post "amqp://guest:***@rabbit:5672/": unsupported protocol scheme "amqp".
04: Restarting krakend
05: Calling krakend endpoint
--> ✅ Success

THANKS A LOT!

{
  "version":3,
  "timeout": "2000ms",
  "port":8080,
  "async_agent": [
    {
      "name": "cool-agent",
      "connection": {
        "max_retries": 10,
        "backoff_strategy":"exponential-jitter",
        "health_interval": "10s"
      },
      "consumer": {
        "topic": "*",
        "workers": 1,
        "timeout": "150ms",
        "max_rate": 0.5
      },
      "backend": [
        {
          "host": [
            "http://127.0.0.1:8080"
          ],
          "url_pattern": "/__debug/"
        }
      ],
      "extra_config": {
        "async/amqp": {
          "host": "amqp://guest:guest@rabbit:5672",
          "name": "krakend",
          "exchange": "foo",
          "durable": true,
          "delete": false,
          "exclusive": false,
          "no_wait": true,
          "prefetch_count": 5,
          "auto_ack": false,
          "no_local": true
        }
      }
    }
  ],
  "endpoints":[
    {
      "endpoint":"/api/user/register-user/{key}",
      "timeout": "2000ms",
      "method":"POST",
      "backend": [{
        "host": ["amqp://guest:guest@rabbit:5672"],
        "disable_host_sanitize": true,
        "extra_config": {
          "backend/amqp/producer": {
            "name": "queue-1",
            "exchange": "some-exchange",
            "durable": true,
            "delete": false,
            "no_wait": true,
            "no_local": false,
            "routing_key": "#",
            "prefetch_count": 10,
            "prefetch_size": 1024,
            "mandatory": false,
            "immediate": false
          }
        }
      }]
    }
  ]
}
docker-compose up

docker-compose.yml
 ...
  krakend_ce:
    container_name: 'api-gateway'
    image: devopsfaith/krakend:latest
    restart: on-failure
    volumes:
      - ./krakend:/etc/krakend
    ports:
      - "1234:1234"
      - "8080:8080"
      - "8090:8090"
    command: ["run", "-d", "-c", "/etc/krakend/krakend.json"]
    depends_on:
      - rabbitmq

Logs
If applicable, any logs you saw in the console and debugging information

api-gateway
[devopsfaith/krakend:latest](https://github.com/devopsfaith/krakend-ce/issues/new?assignees=&labels=question&template=help-and-questions.md&title=)
RUNNING





Parsing configuration file: /etc/krakend/krakend.json

2022/04/27 10:49:17 KRAKEND ERROR: [SERVICE: Logging] Unable to create the logger: getting the extra config for the krakend-gologging module

2022/04/27 10:49:17 KRAKEND DEBUG: [SERVICE: Gin] Debug enabled

2022/04/27 10:49:17 KRAKEND INFO: Starting the KrakenD instance

2022/04/27 10:49:17 KRAKEND INFO: [SERVICE: Gin] Building the router

2022/04/27 10:49:17 KRAKEND DEBUG: [SERVICE: AsyncAgent][cool-agent] Starting the async agent

2022/04/27 10:49:17 KRAKEND DEBUG: [ENDPOINT: cool-agent] Building the proxy pipe

2022/04/27 10:49:17 KRAKEND DEBUG: [BACKEND: /__debug/] Building the backend pipe

2022/04/27 10:49:17 KRAKEND DEBUG: [ENDPOINT: /api/user/register-user/:key] Building the proxy pipe

2022/04/27 10:49:17 KRAKEND DEBUG: [BACKEND: /] Building the backend pipe

2022/04/27 10:49:17 KRAKEND ERROR: [BACKEND: /][AMQP] Error getting the channel for amqp://guest:guest@rabbit:5672/queue-1: dial tcp 172.24.0.2:5672: connect: connection refused

2022/04/27 10:49:17 KRAKEND DEBUG: [ENDPOINT: /api/user/register-user/:key] Building the http handler

2022/04/27 10:49:17 KRAKEND DEBUG: [ENDPOINT: /api/user/register-user/:key][JWTSigner] Signer disabled

2022/04/27 10:49:17 KRAKEND INFO: [ENDPOINT: /api/user/register-user/:key][JWTValidator] Validator disabled for this endpoint

2022/04/27 10:49:17 KRAKEND INFO: [SERVICE: Gin] Listening on port: 8080

2022/04/27 10:49:18 KRAKEND INFO: [SERVICE: AsyncAgent][AMQP][cool-agent] Starting the consumer

2022/04/27 10:49:18 KRAKEND ERROR: [SERVICE: Asyncagent][cool-agent] building the amqp subscriber: dial tcp 172.24.0.2:5672: connect: connection refused

2022/04/27 10:49:20 KRAKEND INFO: [SERVICE: AsyncAgent][AMQP][cool-agent] Starting the consumer

2022/04/27 10:49:20 KRAKEND ERROR: [SERVICE: Asyncagent][cool-agent] building the amqp subscriber: dial tcp 172.24.0.2:5672: connect: connection refused

2022/04/27 10:49:22 KRAKEND DEBUG: [SERVICE: Telemetry] Registering usage stats for Cluster ID a9SodgjZ2GbNIpO/Et3MPJjSs/QjUYbaSO2b8romk4E=

2022/04/27 10:49:23 KRAKEND INFO: [SERVICE: AsyncAgent][AMQP][cool-agent] Starting the consumer

2022/04/27 10:53:55 KRAKEND ERROR: [ENDPOINT: /api/user/register-user/:key] Post "amqp://guest:***@rabbit:5672/": unsupported protocol scheme "amqp"

[GIN] 2022/04/27 - 10:53:55 | 500 |   13.027833ms |      172.24.0.1 | POST     "/api/user/register-user/123"
@github-actions
Copy link

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 15 days.

@alombarte
Copy link
Member

alombarte commented Sep 30, 2022

Planned for KrakenD 2.3 to have retries with different retry strategies

@github-actions
Copy link

This issue was marked as resolved a long time ago and now has been automatically locked as there has not been any recent activity after it. You can still open a new issue and reference this link.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants