Skip to content

Commit

Permalink
spring-web: Akka 2.6 features (#2499).
Browse files Browse the repository at this point in the history
  • Loading branch information
dotbg committed Nov 10, 2020
1 parent 0e37542 commit bd04348
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
7 changes: 6 additions & 1 deletion build.sbt
Expand Up @@ -241,7 +241,12 @@ lazy val pravega = alpakkaProject(
Test / fork := true
)

lazy val springWeb = alpakkaProject("spring-web", "spring.web", Dependencies.SpringWeb)
lazy val springWeb = alpakkaProject(
"spring-web",
"spring.web",
Dependencies.SpringWeb,
fatalWarnings := true
)

lazy val simpleCodecs = alpakkaProject("simple-codecs", "simplecodecs")

Expand Down
Expand Up @@ -4,6 +4,7 @@

package akka.stream.alpakka.spring.web;

import akka.actor.ActorSystem;
import akka.stream.Materializer;
import akka.stream.javadsl.AsPublisher;
import org.springframework.core.ReactiveAdapterRegistry;
Expand All @@ -13,10 +14,10 @@

public class AkkaStreamsRegistrar {

private final Materializer materializer;
private final ActorSystem system;

public AkkaStreamsRegistrar(Materializer mat) {
materializer = mat;
public AkkaStreamsRegistrar(ActorSystem system) {
this.system = system;
}

public void registerAdapters(ReactiveAdapterRegistry registry) {
Expand All @@ -25,15 +26,16 @@ public void registerAdapters(ReactiveAdapterRegistry registry) {
multiValue(akka.stream.javadsl.Source.class, akka.stream.javadsl.Source::empty),
source ->
((akka.stream.javadsl.Source<?, ?>) source)
.runWith(
akka.stream.javadsl.Sink.asPublisher(AsPublisher.WITH_FANOUT), materializer),
.runWith(akka.stream.javadsl.Sink.asPublisher(AsPublisher.WITH_FANOUT), system),
akka.stream.javadsl.Source::fromPublisher);

registry.registerReactiveType(
multiValue(akka.stream.scaladsl.Source.class, akka.stream.scaladsl.Source::empty),
source ->
((akka.stream.scaladsl.Source<?, ?>) source)
.runWith(akka.stream.scaladsl.Sink.asPublisher(true), materializer),
.runWith(
akka.stream.scaladsl.Sink.asPublisher(true),
Materializer.matFromSystem(system)),
akka.stream.scaladsl.Source::fromPublisher);
}
}
Expand Up @@ -16,8 +16,6 @@
// #configure

import akka.actor.ActorSystem;
import akka.stream.ActorMaterializer;
import akka.stream.Materializer;

@Configuration
@ConditionalOnClass(akka.stream.javadsl.Source.class)
Expand All @@ -27,16 +25,14 @@ public class SpringWebAkkaStreamsConfiguration {
private static final String DEFAULT_ACTORY_SYSTEM_NAME = "SpringWebAkkaStreamsSystem";

private final ActorSystem system;
private final ActorMaterializer mat;
private final SpringWebAkkaStreamsProperties properties;

public SpringWebAkkaStreamsConfiguration(final SpringWebAkkaStreamsProperties properties) {
this.properties = properties;
final ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance();

system = ActorSystem.create(getActorSystemName(properties));
mat = ActorMaterializer.create(system);
new AkkaStreamsRegistrar(mat).registerAdapters(registry);
new AkkaStreamsRegistrar(system).registerAdapters(registry);
}

@Bean
Expand All @@ -45,12 +41,6 @@ public ActorSystem getActorSystem() {
return system;
}

@Bean
@ConditionalOnMissingBean(Materializer.class)
public ActorMaterializer getMaterializer() {
return mat;
}

public SpringWebAkkaStreamsProperties getProperties() {
return properties;
}
Expand Down

0 comments on commit bd04348

Please sign in to comment.