score:1
your implementation must be something like this, and hope it helps.
package.scala
package com.app.akka
package object connector {
// do some codes here..
}
cassandraservice.scala
package com.app.akka
import com.app.akka.connector._
object cassandraservice {
def selectfromcassandra() = {
// do some codes here..
}
}
score:1
you have two issue with your current code.
when you compile your package object connector it is throwing below error
error:(14, 35) recursive value executioncontext needs type implicit val executioncontext = executioncontext issue is with implicit val executioncontext = executioncontext line solution for this issue would be as below.
implicit val executioncontext = executioncontext
when we compile cassandraservice then it is throwing error as below
error:(17, 13) cannot find an implicit executioncontext. you might pass an (implicit ec: executioncontext) parameter to your method or import scala.concurrent.executioncontext.implicits.global. rows.map{item =>
error clearly say that either we need to pass executioncontext as implicit parameter or import scala.concurrent.executioncontext.implicits.global. in my system both issues are resolved and its compiled successfully. i have attached code for your reference.
package com.apache.scala
import akka.actor.actorsystem
import akka.stream.actormaterializer
import com.datastax.driver.core.cluster
import scala.concurrent.executioncontext
package object connector {
implicit val system = actorsystem()
implicit val mat = actormaterializer()
implicit val executioncontext = executioncontext
implicit val session = cluster
.builder
.addcontactpoints("localhost")
.withport(9042)
.build()
.connect()
}
package com.apache.scala.connector
import akka.stream.alpakka.cassandra.scaladsl.cassandrasource
import akka.stream.scaladsl.sink
import com.datastax.driver.core.{row, simplestatement}
import scala.collection.immutable
import scala.concurrent.executioncontext.implicits.global
import scala.concurrent.future
object cassandraservice {
def selectfromcassandra() = {
val statement = new simplestatement(s"select * from animals.alpakka").setfetchsize(20)
val rows: future[immutable.seq[row]] = cassandrasource(statement).runwith(sink.seq)
rows.map{item =>
print(item)
}
}
}
Source: stackoverflow.com
Related Query
- Using Scala class defined in package object from Java
- Using vals from scala package object in java
- How to import own scala package using spark-shell?
- Using Multinomial Distribution with Scala and Breeze package
- Using sbt to package scala source code in cmd : error missing 'SparkContext.class'
- Using Scala and reflection to list an array of classes in a package
- Using multi-line inputs Scala process package
- Basic blob download fails using com.azure.storage.blob package with java.nio.channels.ClosedChannelException in Scala
- Using private package classes in Scala repl
- Error:(3, 25) object ml is not a member of package org.apache.flink import org.apache.flink.ml.MLUtils in flink using scala
- scala implicit conversion error on java generic type while using thirdparty java package
- Pros and cons of using sbt vs maven in Scala project
- How to update a mongo record using Rogue with MongoCaseClassField when case class contains a scala Enumeration
- How to parse JSON in Scala using standard Scala classes?
- Difference between using App trait and main method in scala
- Class broken error with Joda Time using Scala
- Scala capture group using regex
- Using Scala traits with implemented methods in Java
- Scala on iOS using Avian
- Using varargs from Scala
- Scala import not working - object <name> is not a member of package, sbt preppends current package namespace in imports
- Using Either to process failures in Scala code
- How to reload a class or package in Scala REPL?
- Using partial functions in Scala - how does it work?
- Using Scala from Java: passing functions as parameters
- Using scala constructor to set variable defined in trait
- Using Eithers with Scala "for" syntax
- Why are classes inside Scala package objects dispreferred?
- Scala: How can I replace value in Dataframes using scala
- FoldLeft using FoldRight in scala
More Query from same tag
- Immutable DataStructures In Scala
- Package object for one-liner Scala classes
- Scala Await a expired Future doesn't see TimeoutException
- Passing sys props to Spark 1.5 especially properties with spaces in it
- Monad transformers - Scalaz - List[Future[String\/String]] to Future[String\/String]
- Referencing vals in method returning new trait instance inside trait
- Scala Type Syntax
- Scala Annotation List?
- scalaz stream structure for growing lists
- How to check if element exist in three lists using scala?
- Sbt-assembly, Ivy, classpath
- scala is using akka shipped with binary distribution instead of sbt 's one
- How to create json string from scala ArrayBuffer
- Why builder design pattern is used to create Spark Session?
- Using upper-bounds for immutable collections
- How to send a process to multiple sinks in scalaz-stream
- Transforming List to Seq of tuples of attributes in Scala?
- Scala - Using Filter to see if the value in one list matches the value in the same index in another list
- how to set main class in SBT 0.13 project
- Can't seem to repeat reducebykey twice -- what is the new data structure?
- Why Scala last val is not the return value?
- Free monad - implicit Inject with nested Coproduct using cats
- Handling type erasure of nested Observable in groupBy
- Testing Akka Typed behavior
- Consume a source with two sinks and get the result of one sink
- Passing parameters to scalameta paradise macro
- Calling Java/Scala function from a task
- Play framework "Connection reset by peer"
- How can I parse an object of a bounded type T from JSON from an implicit request?
- Extracting Data From Azure SQL database using Akka.io