score:5
akka streams at this point requires a "classic" (untyped) actorsystem
which can be implicitly converted into a materializer.
so if materializing a stream inside an akka typed behavior
, one would
implicit val materializer = context.classicactorcontext.system
and if materializing a stream outside of an actor but where you have a typed actorsystem
:
implicit val materializer = typedactorsystem.classicsystem
as mentioned by @johanandren, one can also put the typed actorsystem
in the implicit scope, which will allow the implicit conversion to materializer
to take effect.
implicit val system = context.system
score:3
the akka documentation for 2.6.x indicates that actormaterializer is deprectated: "use the system wide materializer or materializer.apply(actorcontext) with stream attributes or configuration settings to change defaults."
use this instead:
import akka.done
import akka.actor.actorsystem
import akka.actor.typed.behavior
import akka.actor.typed.scaladsl.behaviors
import akka.stream.materializer
object main {
def main(args: array[string]) : unit = {
val guardian: behavior[done] = behaviors.setup(_ => {
behaviors.receivemessage{
case done => behaviors.stopped
}
})
val as = actorsystem()
val materializer = materializer(as)
}
}
score:6
previous answers are halfways to the indended new api.
the typed actorsystem
can be implicitly transformed to provide the system materialiser as well, so just having it available as an implicit should be enough.
for example:
behaviors.setup { ctx =>
implicit val system = ctx.system
source(1 to 10).runforeach(println)
...
}
the inner working of this is an implicit conversion available from the materializer
companion object that extracts the system materializer of a classicactorsystemprovider
into a materializer
. both the typed and the classic actorsystem
implements classicactorsystemprovider
.
Source: stackoverflow.com
Related Query
- How to instantiate a materializer for AkkaStreams when I have a reference to the typed actor system?
- How do I write a JSON Format for an object in the Java library that doesn't have an apply method?
- Spark: unpersist RDDs for which I have lost the reference
- How does HList.foldRight look for implicits when used in the implementation of a type class?
- When using shapeless.Generic, how to avoid the error 'super constructor cannot be passed a self reference unless parameter is declared by-name'?
- How do I get circe to have an either/or output scenario for the generated Json?
- How to unhide the unchecked warning when ClassTag is synthesised for a type with erased parameters?
- Scala compilers complains about "ambiguous reference to overloaded definition" when asking for a function in the second parameters set
- How can be CSS used to style web pages meant to be served by Lift when Lift uses CSS classes for the purpose of its own?
- How to delete duplicates from a file when other fields are varying. We have to just remove the duplicates based on one column
- How to ensure type safety with Scala's Refined library when using the same predicate for refinement
- how to set the scala compiler when the scala file has chinese char for comments
- How do I create a child Akka2 actor when all I have is an ActorRef to the parent?
- How to load the ReactiveMongo for both linux and osx when defining the dependancies?
- How to signal the Sink when all elements have been processed?
- How to construct predicate for HashMap::retain when the value is a tuple?
- how to reference a specific function where two functions in scope have the same name
- How to create an inner class instance while using alias name for referring the outer class "this" reference
- How to test if the case classes I have created for the parser are correct using json4s libraries in scala?
- How to organise the entity model for play framework 2 when working with anorm
- Akka HTTP: How to have the flow Http().superPool() not throw exceptions when encountering a bad URL?
- how to apply joins in spark scala when we have multiple values in the join column
- In Spark windowing, how do you fill null for when the number of rows selected are less than window size?
- i have wriiten a logout code in welcome.scala.html page but getting errors in that page how can i write the code for it
- How do I make a trait that I can mix into mapped fields to that I don not have to override the same properties for many fields in a database?
- Is there a way for a Scala base class to get informed when all the derived classes have been constructed? (guess not)
- What are the relationships between Any, AnyVal, AnyRef, Object and how do they map when used in Java code?
- What are the precise rules for when you can omit parenthesis, dots, braces, = (functions), etc.?
- How the get the classOf for a scala object type
- How can I get complete stacktraces for exceptions thrown in tests when using sbt and testng?
More Query from same tag
- Unable to insert data to MongoDB from Spark without MongoSpark
- Error while moving a file into HDFS from Local using Scala
- Pattern Matching chooses the wrong case if used with ClassTag
- What is `Something#A` in scala
- PlaySpecification not found in Play 2.6.3
- Scala Copy() Odd Behavior
- How can I serialize val element in Json
- Playframework 2.0 define function in View Template
- How to get a handle to the TableView from the controller in scalafx
- Shuffled vs non-shuffled coalesce in Apache Spark
- clojure iterate equivalent in scala?
- How to deserialize Avro messages from Kafka in Flink (Scala)?
- Play framework template for cycle
- Restart PlayConsole SBT server
- Zeppelin does not see dependencies from custom repository
- Batch inserts and LAST_INSERT_ID with Slick and MariaDB
- Apache Spark - Tweets Processing
- Using google guava error - Not under a public suffix: display_url
- How do I handle undefined class objects passed as function arguments?
- Reading a local Windows file in apache Spark
- Jetty error: HTTP method GET is not supported by this URL
- How to listen websocket server close events using akka-http websocket client
- How to allow None value to be accepted in dataframe in Spark 2?
- Converting List to Map using keys in Scala
- How to call Z3_get_version() from Microsoft.Z3.dll from Java
- Jackson mapper with generic class in scala
- Is there some way to use MacroImplementations code for "f" string interpolator in my macro?
- java.lang.NoClassDefFoundError: org/apache/logging/log4j/Logger
- IntelliJ unable to resolve certain types, ex: EnumValue on a Mongo record - Scala
- How to drop values duplicated in column?