Skip to content

Commit

Permalink
tmp: new API
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Nov 27, 2024
1 parent 9279f9f commit 82a89a2
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
import io.quarkus.logging.Log;
import xyz.block.ftl.Export;
import xyz.block.ftl.Subscription;
import xyz.block.ftl.WriteableTopic;
import xyz.block.ftl.Topic;
import xyz.block.ftl.TopicDefinition;
import xyz.block.ftl.Verb;

public class Publisher {

@Export
@TopicDefinition("testTopic")
interface TestTopic extends Topic<PubSubEvent> {
@Topic("testTopic")
interface TestTopic extends WriteableTopic<PubSubEvent> {

}

@TopicDefinition("localTopic")
interface LocalTopic extends Topic<PubSubEvent> {
@Topic("localTopic")
interface LocalTopic extends WriteableTopic<PubSubEvent> {

}

@Export
@TopicDefinition("topic2")
interface Topic2 extends Topic<PubSubEvent> {
@Topic("topic2")
interface Topic2 extends WriteableTopic<PubSubEvent> {

}

Expand All @@ -49,7 +49,7 @@ void publishOneToTopic2(Topic2 topic2) throws Exception {
topic2.publish(new PubSubEvent().setTime(t));
}

@Subscription(topicClass = LocalTopic.class, name = "localSubscription")
@Subscription(topic = LocalTopic.class)
public void local(TestTopic testTopic, PubSubEvent event) {
testTopic.publish(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ public class Subscriber {

private static final AtomicInteger catchCount = new AtomicInteger();

@TestTopicSubscription
@Subscription(topic = TestTopic.class)
void consume(PubSubEvent event) throws Exception {
Log.infof("Subscriber is consuming %s", event.getTime());
}

@Subscription(topic = "topic2", module = "publisher", name = "doomedSubscription")
@Subscription(topic = Topic2.class)
@Retry(count = 2, minBackoff = "1s", maxBackoff = "1s", catchVerb = "catch")
public void consumeButFailAndRetry(PubSubEvent event) {
throw new RuntimeException("always error: event " + event.getTime());
}

@Subscription(topic = "topic2", module = "publisher", name = "doomedSubscription2")
@Subscription(topic = Topic2.class)
@Retry(count = 1, minBackoff = "1s", maxBackoff = "1s", catchVerb = "catchAny")
public void consumeButFailAndCatchAny(PubSubEvent event) {
throw new RuntimeException("always error: event " + event.getTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import xyz.block.ftl.LeaseClient;
import xyz.block.ftl.Secret;
import xyz.block.ftl.Subscription;
import xyz.block.ftl.TopicDefinition;
import xyz.block.ftl.Topic;
import xyz.block.ftl.TypeAlias;
import xyz.block.ftl.TypeAliasMapper;
import xyz.block.ftl.Verb;
Expand All @@ -34,5 +34,5 @@ private FTLDotNames() {
public static final DotName SUBSCRIPTION = DotName.createSimple(Subscription.class);
public static final DotName LEASE_CLIENT = DotName.createSimple(LeaseClient.class);
public static final DotName GENERATED_REF = DotName.createSimple(GeneratedRef.class);
public static final DotName TOPIC_DEFINITION = DotName.createSimple(TopicDefinition.class);
public static final DotName TOPIC_DEFINITION = DotName.createSimple(Topic.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.jboss.jandex.IndexView;

import io.quarkus.builder.item.SimpleBuildItem;
import xyz.block.ftl.Topic;
import xyz.block.ftl.WriteableTopic;

public final class SubscriptionMetaAnnotationsBuildItem extends SimpleBuildItem {

Expand All @@ -33,11 +33,11 @@ public static SubscriptionAnnotation fromJandex(IndexView indexView, AnnotationI
AnnotationValue topicClassValue = subscriptions.value("topicClass");
String topicName;
if (topicValue != null && !topicValue.asString().isEmpty()) {
if (topicClassValue != null && !topicClassValue.asClass().name().toString().equals(Topic.class.getName())) {
if (topicClassValue != null && !topicClassValue.asClass().name().toString().equals(WriteableTopic.class.getName())) {
throw new IllegalArgumentException("Cannot specify both topic and topicClass");
}
topicName = topicValue.asString();
} else if (topicClassValue != null && !topicClassValue.asClass().name().toString().equals(Topic.class.getName())) {
} else if (topicClassValue != null && !topicClassValue.asClass().name().toString().equals(WriteableTopic.class.getName())) {
var topicClass = indexView.getClassByName(topicClassValue.asClass().name());
AnnotationInstance annotation = topicClass.annotation(FTLDotNames.TOPIC_DEFINITION);
if (annotation == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import io.quarkus.gizmo.ClassCreator;
import io.quarkus.gizmo.MethodDescriptor;
import xyz.block.ftl.Export;
import xyz.block.ftl.Topic;
import xyz.block.ftl.WriteableTopic;
import xyz.block.ftl.runtime.TopicHelper;
import xyz.block.ftl.v1.schema.Decl;

public class TopicsProcessor {

public static final DotName TOPIC = DotName.createSimple(Topic.class);
public static final DotName TOPIC = DotName.createSimple(WriteableTopic.class);
private static final Logger log = Logger.getLogger(TopicsProcessor.class);

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package xyz.block.ftl;

/**
* Marker interface for a topic that can be subscribed to, it must be extended and annotated with {@code @TopicDefinition}.
*/
public interface ConsumableTopic {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,10 @@
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
public @interface Subscription {
/**
* @return The module of the topic to subscribe to, if empty then the topic is assumed to be in the current module.
*/
String module() default "";

/**
*
* @return The name of the topic to subscribe to. Cannot be used in conjunction with {@link #topicClass()}.
*/
String topic() default "";

/**
*
* @return The subscription name
*/
String name();

/**
* The class of the topic to subscribe to, which can be used in place of directly specifying the topic name and module.
*/
Class<? extends Topic> topicClass() default Topic.class;
Class<? extends ConsumableTopic> topic() default ConsumableTopic.class;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package xyz.block.ftl;

/**
* A concrete definition of a topic. Extend this interface and annotate with {@code @TopicDefinition} to define a topic,
* then inject this into verb methods to publish to the topic.
*
* @param <T>
*/
public interface Topic<T> {
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Topic {
/**
*
* @return The name of the topic
*/
String value();

void publish(T object);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package xyz.block.ftl;

/**
* A concrete definition of a topic. Extend this interface and annotate with {@code @TopicDefinition} to define a topic,
* then inject this into verb methods to publish to the topic.
*
* @param <T>
*/
public interface WriteableTopic<T> extends ConsumableTopic {

void publish(T object);
}

0 comments on commit 82a89a2

Please sign in to comment.