generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e31d24d
commit 44dfa04
Showing
11 changed files
with
172 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module = "publisher" | ||
language = "java" |
14 changes: 14 additions & 0 deletions
14
backend/controller/pubsub/testdata/kotlin/publisher/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>xyz.block.ftl.examples</groupId> | ||
<artifactId>publisher</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<parent> | ||
<groupId>xyz.block.ftl</groupId> | ||
<artifactId>ftl-build-parent-kotlin</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
</project> |
6 changes: 6 additions & 0 deletions
6
...estdata/kotlin/publisher/src/main/kotlin/xyz/block/ftl/java/test/publisher/PubSubEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package xyz.block.ftl.java.test.publisher | ||
|
||
import java.time.ZonedDateTime | ||
class PubSubEvent(var time: ZonedDateTime) { | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
.../testdata/kotlin/publisher/src/main/kotlin/xyz/block/ftl/java/test/publisher/Publisher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package xyz.block.ftl.java.test.publisher | ||
|
||
import io.quarkus.logging.Log | ||
import xyz.block.ftl.* | ||
import java.time.ZonedDateTime | ||
|
||
class Publisher { | ||
@Export | ||
@Topic("testTopic") | ||
interface TestTopic : WriteableTopic<PubSubEvent?> | ||
|
||
@Topic("localTopic") | ||
interface LocalTopic : WriteableTopic<PubSubEvent?> | ||
|
||
@Export | ||
@Topic("topic2") | ||
interface Topic2 : WriteableTopic<PubSubEvent?> | ||
|
||
@Verb | ||
@Throws(Exception::class) | ||
fun publishTen(testTopic: LocalTopic) { | ||
for (i in 0..9) { | ||
val t = ZonedDateTime.now() | ||
Log.infof("Publishing %s", t) | ||
testTopic.publish(PubSubEvent(t)) | ||
} | ||
} | ||
|
||
@Verb | ||
@Throws(Exception::class) | ||
fun publishOne(testTopic: TestTopic) { | ||
val t = ZonedDateTime.now() | ||
Log.infof("Publishing %s", t) | ||
testTopic.publish(PubSubEvent(t)) | ||
} | ||
|
||
@Verb | ||
@Throws(Exception::class) | ||
fun publishOneToTopic2(topic2: Topic2) { | ||
val t = ZonedDateTime.now() | ||
Log.infof("Publishing %s", t) | ||
topic2.publish(PubSubEvent(t)) | ||
} | ||
|
||
@Subscription(topic = LocalTopic::class, from = FromOffset.LATEST) | ||
fun local(testTopic: TestTopic, event: PubSubEvent) { | ||
testTopic.publish(event) | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
backend/controller/pubsub/testdata/kotlin/subscriber/ftl.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module = "subscriber" | ||
language = "java" |
14 changes: 14 additions & 0 deletions
14
backend/controller/pubsub/testdata/kotlin/subscriber/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>xyz.block.ftl.examples</groupId> | ||
<artifactId>subscriber</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<parent> | ||
<groupId>xyz.block.ftl</groupId> | ||
<artifactId>ftl-build-parent-kotlin</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
</project> |
73 changes: 73 additions & 0 deletions
73
...stdata/kotlin/subscriber/src/main/kotlin/xyz/block/ftl/java/test/subscriber/Subscriber.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package xyz.block.ftl.java.test.subscriber | ||
|
||
import ftl.builtin.CatchRequest | ||
import ftl.publisher.PubSubEvent | ||
import ftl.publisher.TestTopicTopic | ||
import ftl.publisher.Topic2Topic | ||
import io.quarkus.logging.Log | ||
import xyz.block.ftl.* | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
class Subscriber { | ||
@Subscription(topic = TestTopicTopic::class, from = FromOffset.BEGINNING) | ||
@Throws( | ||
Exception::class | ||
) | ||
fun consume(event: PubSubEvent) { | ||
Log.infof("Subscriber is consuming %s", event.time) | ||
} | ||
|
||
@Subscription(topic = Topic2Topic::class, from = FromOffset.BEGINNING) | ||
@Retry(count = 2, minBackoff = "1s", maxBackoff = "1s", catchVerb = "catch") | ||
fun consumeButFailAndRetry(event: PubSubEvent) { | ||
throw RuntimeException("always error: event " + event.time) | ||
} | ||
|
||
@Subscription(topic = Topic2Topic::class, from = FromOffset.BEGINNING) | ||
@Retry(count = 1, minBackoff = "1s", maxBackoff = "1s", catchVerb = "catchAny") | ||
fun consumeButFailAndCatchAny(event: PubSubEvent) { | ||
throw RuntimeException("always error: event " + event.time) | ||
} | ||
|
||
@Verb | ||
@VerbName("catch") | ||
fun catchVerb(req: CatchRequest<PubSubEvent?>) { | ||
if (!req.error.contains("always error: event")) { | ||
throw RuntimeException("unexpected error: " + req.error) | ||
} | ||
if (catchCount.incrementAndGet() == 1) { | ||
throw RuntimeException("catching error") | ||
} | ||
} | ||
|
||
@Verb | ||
fun catchAny(req: CatchRequest<Any>) { | ||
require("subscriber" == req.verb.module) { String.format("unexpected verb module: %s", req.verb.module) } | ||
require("consumeButFailAndCatchAny" == req.verb.name) { | ||
String.format( | ||
"unexpected verb name: %s", | ||
req.verb.name | ||
) | ||
} | ||
require("publisher.PubSubEvent" == req.requestType) { | ||
String.format( | ||
"unexpected request type: %s", | ||
req.requestType | ||
) | ||
} | ||
require(req.request is Map<*, *>) { | ||
String.format( | ||
"expected request to be a Map: %s", | ||
req.request.javaClass.name | ||
) | ||
} | ||
val request = req.request as Map<*, *> | ||
val time = request["time"] | ||
requireNotNull(time) { "expected request to have a time key" } | ||
require(time is String) { "expected request to have a time value of type string" } | ||
} | ||
|
||
companion object { | ||
private val catchCount = AtomicInteger() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters