Skip to content

Commit

Permalink
Fixed Java issue in Subscription DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
johanhaleby committed Jan 26, 2024
1 parent 33dcc4e commit 3c1af7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
### Next version
* Fixed issue in [Subscription DSL](https://occurrent.org/documentation#subscription-dsl) when using "subscribe" functions with a single event type different from the "base event type", i.e. this didn't work in previous version in Java:
```java
// GameEvent is the "base event type"
Subscriptions<GameEvent> subsctriptions = new Subscriptions<>(..);

// GameStarted has GameEvent as parent, the following didn't compile in version 0.17.0
subscriptions.subscribe("ikk", GameStarted.class, gameStarted -> System.out.println("gameStarted: " + gameStarted));
```

### 0.17.0 (2024-01-19)
* spring-boot-starter-mongodb no longer autoconfigures itself by just importing the library in the classpath, instead you need to bootstrap by annotating your Spring Boot class with @EnableOccurrent.
* Fixed bug in spring-boot-starter-mongodb module in which it didn't automatically configure MongoDB.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,18 @@ class Subscriptions<E : Any>(private val subscriptionModel: Subscribable, privat
}

@JvmOverloads
fun <E1 : E> subscribe(subscriptionId: String, eventType: Class<E>, startAt: StartAt? = null, fn: Consumer<E1>): Subscription {
fun <E1 : E> subscribe(subscriptionId: String, eventType: Class<E1>, startAt: StartAt? = null, fn: Consumer<E1>): Subscription {
return subscribe(subscriptionId, listOf(eventType), startAt) { e : E ->
@Suppress("UNCHECKED_CAST")
fn.accept(e as E1)
}
}

@JvmOverloads
fun <E1 : E> subscribe(subscriptionId: String, eventType: Class<E>, startAt: StartAt? = null, fn: BiConsumer<EventMetadata, E>): Subscription {
fun <E1 : E> subscribe(subscriptionId: String, eventType: Class<E1>, startAt: StartAt? = null, fn: BiConsumer<EventMetadata, E1>): Subscription {
return subscribe(subscriptionId, listOf(eventType), startAt) { metadata, e ->
fn.accept(metadata, e)
@Suppress("UNCHECKED_CAST")
fn.accept(metadata, e as E1)
}
}

Expand Down

0 comments on commit 3c1af7d

Please sign in to comment.