matsluni/aws-spi-akka-http

Creates a brand new aws-akka-http actor system and loads all the akka plugins unnecessarily even when a custom system is used

Closed this issue · 6 comments

implicit val as = actorSystem.getOrElse(ActorSystem("aws-akka-http"))

ennru commented

Passing the already existing actor system (which ends up in the actorSystem above is illustrated in the readme.

@ennru Thanks for your reply. I agree, that this is covered in the readme.

Also, maybe a good time to think about #7 again.

Yes, you can use your custom system, however, it still creates an aws-akka-http that is not used
This line needs to be a supplier and not a value

implicit val as = actorSystem.getOrElse(ActorSystem("aws-akka-http")) 

should be

implicit val as = actorSystem.getOrElse(() => ActorSystem("aws-akka-http")) 

Otherwise, if you have any akka plugins such as persistence in your akka config, it will start initializing DB connections for that aws-akka-http system

[service] [2020-12-18 04:53:08,645] INFO  [aws-akka-http-akka.actor.default-dispatcher-6] [akka.event.slf4j.Slf4jLogger] [] - Slf4jLogger started 
[service] [2020-12-18 04:53:08,724] INFO  [aws-akka-http-akka.actor.default-dispatcher-6] [akka.persistence.Persistence] [Persistence(akka://aws-akka-http)] - Auto-starting journal plugin `jdbc-journal` 
[service] [2020-12-18 04:53:08,733] INFO  [aws-akka-http-akka.actor.default-dispatcher-6] [akka.persistence.Persistence] [Persistence(akka://aws-akka-http)] - Auto-starting snapshot store `jdbc-snapshot-store` 
[service] [2020-12-18 04:53:08,827] INFO  [aws-akka-http-akka.actor.default-dispatcher-6] [akka.actor.ActorSystemImpl] [akka.actor.ActorSystemImpl(aws-akka-http)] - Creating an akka persistence JDBC database instance... 
[service] [2020-12-18 04:53:08,828] INFO  [aws-akka-http-akka.persistence.dispatchers.default-plugin-dispatcher-9] [com.zaxxer.hikari.HikariDataSource] [] - slick.db - Starting... 
[service] [2020-12-18 04:53:08,831] INFO  [aws-akka-http-akka.persistence.dispatchers.default-plugin-dispatcher-9] [com.zaxxer.hikari.HikariDataSource] [] - slick.db - Start completed. 
[service] [2020-12-18 04:53:08,837] INFO  [aws-akka-http-akka.persistence.dispatchers.default-plugin-dispatcher-8] [com.zaxxer.hikari.HikariDataSource] [] - slick.db - Starting... 
[service] [2020-12-18 04:53:08,839] INFO  [aws-akka-http-akka.actor.default-dispatcher-6] [akka.actor.ActorSystemImpl] [akka.actor.ActorSystemImpl(aws-akka-http)] - Creating an akka persistence JDBC database instance... 
[service] [2020-12-18 04:53:08,846] INFO  [aws-akka-http-akka.persistence.dispatchers.default-plugin-dispatcher-8] [com.zaxxer.hikari.HikariDataSource] [] - slick.db - Start completed. 

It's insane

ennru commented

getOrElse is call-by-name, so it doesn't require a supplier function:

Some(42).getOrElse(sys.error("this doesn't happen"))

Something else must be going on.

The only other places i use it is here

val awsClient:software.amazon.awssdk.services.kinesis.KinesisAsyncClient = _

akka.stream.alpakka.kinesis.javadsl.KinesisFlow.create(kinesisStreamName, KinesisFlowSettings.create(), awsClient);
  public static KinesisAsyncClient make(AwsConfig config) {
        KinesisAsyncClientBuilder builder = KinesisAsyncClient.builder();
        config.kinesisEndpointOverride.ifPresent(
          builder::endpointOverride
        );
        builder.region(config.region);
        return builder.build();
    }

and here

@Provides
	@Singleton
	public SqsAsyncClient getSqsAsyncClient(ActorSystem system, AwsConfig awsConfig){

		SqsAsyncClientBuilder builder = SqsAsyncClient.builder().region(awsConfig.region);

		builder =
		  awsConfig.sqsEndpointOverride.map(builder::endpointOverride).orElse(builder)
			.httpClient(
		  		AkkaHttpClient.builder().withActorSystem(system).build()
			);

		SqsAsyncClient sqsClient = builder.build();

		system.registerOnTermination(sqsClient::close);

		return sqsClient;
	}

looks like i have to explicitly override kinesis http client or else it picks up the default implementation from the classpath which ends up being akka http client with the default actor system... that should probably be in bold letters as a warning to others