quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.73k stars 2.67k forks source link

add a switch to disable @Incoming just like @Scheduled myMethod.cron.expr=disabled #19318

Closed Dieken closed 3 years ago

Dieken commented 3 years ago

Description

This is to seek a specific solution for https://github.com/quarkusio/quarkus/issues/19278.

I have a simple Quarkus app that includes both HTTP API and Kafka consumer, I would like to run a HTTP API only version and a fully version in my K8S cluster. Because the code base is very small, I don't want to separate code into three jars: common service jar + http resource jar + kafka consumer jar. Because I don't hope the Kafka consuming issue affects HTTP API service performance and stability, I want that HTTP API only version.

So I want a switch to disable @Incoming:

@ApplicationScoped
public class MyConsumer {
    @Incoming("topicA")
    public void consume(Xxx x) {
    }
}

application.properties:

mp.messaging.incoming.topicA.disabled=true     # currently Quarkus doesn't support this config property

Implementation ideas

Add a new runtime config property like mp.messaging.incoming.[TOPIC].disabled with default value false.

quarkus-bot[bot] commented 3 years ago

/cc @mkouba

Dieken commented 3 years ago

It should be labeled area/reactive-messaging. CC @Ladicek @cescoffier @manovotn

Ladicek commented 3 years ago

I think the common naming style would actually be mp.messaging.incoming|outgoing.<channel>.enabled, and the default would of course be true. Other than that, this seems quite sensible to me. WDYT @ozangunalp?

ozangunalp commented 3 years ago

Funny enough there already is an option to disable a channel with mp.messaging.incoming|outgoing.<channel>.enabled=false. It prevents the channel from being registered.

ozangunalp commented 3 years ago

And my bad that it is not documented inside the Kafka reference guide. I don't think that it is in Microprofile Reactive Messaging spec.

ozangunalp commented 3 years ago

@Dieken can you give it a try and tell us if it works you'd expect?

Dieken commented 3 years ago

@ozangunalp it does disable the channel 😄

But it makes health check failed even with mp.messaging.incoming.my-topic.health-enabled=false:

 curl localhost:8080/q/health

{
    "status": "DOWN",
    "checks": [
        {
            "name": "SmallRye Reactive Messaging - liveness check",
            "status": "DOWN",
            "data": {
                "kafka-connector": "[KO]"
            }
        },
        {
            "name": "Database connections health check",
            "status": "UP"
        },
        {
            "name": "Reactive MySQL connections health check",
            "status": "UP",
            "data": {
                "<default>": "up"
            }
        },
        {
            "name": "SmallRye Reactive Messaging - readiness check",
            "status": "DOWN",
            "data": {
                "kafka-connector": "[KO]"
            }
        }
    ]
}

I hope it says "[OK] - no subscription yet, so no connection to the Kafka broker yet" like this:

curl localhost:8080/q/health

{
    "status": "UP",
    "checks": [
        {
            "name": "SmallRye Reactive Messaging - liveness check",
            "status": "UP",
            "data": {
                "qieman-user": "[OK]"
            }
        },
        {
            "name": "Database connections health check",
            "status": "UP"
        },
        {
            "name": "Reactive MySQL connections health check",
            "status": "UP",
            "data": {
                "<default>": "up"
            }
        },
        {
            "name": "SmallRye Reactive Messaging - readiness check",
            "status": "UP",
            "data": {
                "qieman-user": "[OK] - no subscription yet, so no connection to the Kafka broker yet"
            }
        }
    ]
}

@Ladicek

Ladicek commented 3 years ago

Sounds like a bug to me. Disabled channels IMHO shouldn't participate in health at all.

Ladicek commented 3 years ago

OK so this is clearly a case of connector existing, but having no sources nor sinks. Precisely what I thought shouldn't exist :-)

Ladicek commented 3 years ago

This PR to Reactive Messaging should fix that: https://github.com/smallrye/smallrye-reactive-messaging/pull/1346

Dieken commented 3 years ago

This PR to Reactive Messaging should fix that: smallrye/smallrye-reactive-messaging#1346

Great! Hope this is included in Quarkus >= 2.1.2.Final with smallrye-reactive-messaging 3.9.0, currently Quarkus 2.1.1.Final ships smallrye-reactive-messaging 3.7.1.

Ladicek commented 3 years ago

This will be fixed by upgrading to SmallRye Reactive Messaging 3.9.0, which should hopefully happen in Quarkus 2.2.

cescoffier commented 3 years ago

Just to answer @ozangunalp question, the 'enabled' channel is not part of the spec. This is smallrye specific.