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

Missing @Singleton #633

Merged
merged 3 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.micronaut.configuration.kafka.docs.producer.fallback;
package docs.producer.fallback;

import io.micronaut.configuration.kafka.annotation.KafkaClient;
import io.micronaut.configuration.kafka.annotation.Topic;
import io.micronaut.context.annotation.Requires;

@Requires(property = "spec.name", value = "MessageClientFallbackSpec")
@KafkaClient
public interface MessageClient {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package io.micronaut.configuration.kafka.docs.producer.fallback;
package docs.producer.fallback;

// tag::imports[]
import io.micronaut.context.annotation.Replaces;
import io.micronaut.context.annotation.Requires;
import io.micronaut.core.util.StringUtils;
import jakarta.inject.Singleton;
// end::imports[]

@Requires(property = "spec.name", value = "MessageClientFallbackSpec")
// tag::clazz[]
@Requires(property = "kafka.enabled", notEquals = StringUtils.TRUE, defaultValue = StringUtils.TRUE) // <1>
@Replaces(MessageClient.class) // <2>
@Singleton
public class MessageClientFallback implements MessageClient { // <3>

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package docs.producer.fallback

import io.micronaut.context.ApplicationContext
import io.micronaut.context.annotation.Property
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import jakarta.inject.Inject
import spock.lang.Specification

@MicronautTest
@Property(name = "spec.name", value = "MessageClientFallbackSpec")
@Property(name = "kafka.enabled", value = "false")
class MessageClientFallbackSpec extends Specification {

@Inject
ApplicationContext context

void "test that context contains the fallback bean"() {
when:
MessageClientFallback bean = context.getBean(MessageClientFallback)

then:
bean != null

when:
bean.send('message')

then:
thrown(UnsupportedOperationException)
}
}
4 changes: 2 additions & 2 deletions src/main/docs/guide/kafkaApplications/kafkaDisabled.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ You must, however, provide your own replacement implementations of any `@KafkaCl
.Creating Replacement KafkaClient Implementations
[source,java]
----
include::{testskafka}/producer/fallback/MessageClientFallback.java[tags=imports, indent=0]
include::kafka/src/test/groovy/docs/producer/fallback/MessageClientFallback.java[tags=imports, indent=0]

include::{testskafka}/producer/fallback/MessageClientFallback.java[tags=clazz, indent=0]
include::kafka/src/test/groovy/docs/producer/fallback/MessageClientFallback.java[tags=clazz, indent=0]
----

<1> Only instantiate when `kafka.enabled` is set to `false`
Expand Down