Comments (7)
The TypeTaggedTrait is there to add the type tag derived from the extending class as a value. This allows preserving the type information in the runtime that would be otherwise lost due to type erasure. This is especially nice when combined with Akka actors where each message loses its type information. The problem that TypeTaggedTrait has is that it doesn't deal very well with inheritance: the cast operation matches on exact type rather than being aware of the type hierarchy.
Here's some additional reading on the subject, if you're interested: https://www.cakesolutions.net/teamblogs/ways-to-pattern-match-generic-types-in-scala
from scala-kafka-client.
Try moving the definition of the MyDummy case class above the test case definition, to avoid this problem.
from scala-kafka-client.
Cool! That got rid of the problem. But is there an explanation as to how this solves the problem? Curious to know?
from scala-kafka-client.
Not exactly sure. The TypeTag feature relies on reflection and implicits, which are prone to this kind of weirdness...
from scala-kafka-client.
How could I understand the TypeTaggedTrait? The code looks super simple and awesome but I can't reason out what this trait is actually doing! Could you please give me a short explanation?
from scala-kafka-client.
I do understand the TypeTag in Scala and why it is needed. I wanted to understand what roles does the TypeTaggedTrait play in the application. For example., the ProducerRecord usage is like this:
final case class ProducerRecords[Key: TypeTag, Value: TypeTag](
records: Iterable[ProducerRecord[Key, Value]],
successResponse: Option[Any] = None,
failureResponse: Option[Any] = None
) extends TypeTagged[ProducerRecords[Key, Value]]
How does each of the methods implemented in the TypeTaggedTrait relate to the ProducerRecords?
from scala-kafka-client.
It's there so that the actors that receive those records (in this case the producer actor), can pattern match on only ProducerRecords[MyKey, MyString]
and not on any other ProducerRecords
with different type parameters.
The pattern match for the producer actor is effectively a function from Any => Option[ProducerRecords[MyKey, MyString]
where MyKey
and MyString
are any custom type parameters. If the input is of type TypeTaggedTrait
, then we know that it has a cast
method. We can use that cast method to attempt to cast the value to ProducerRecords[MyKey, MyString]
, which will work if only if the value is of type ProducerRecords
and it has the MyKey
and MyString
type parameters. Otherwise it will return None
, i.e. it's not a match. See TypeTaggedExtractor for the implementation details.
from scala-kafka-client.
Related Issues (20)
- Weird exception when using Protobuf messages
- Endless Loop HOT 3
- Typo in https://github.com/cakesolutions/scala-kafka-client/wiki/KafkaConsumerActor-Configuration HOT 1
- Error in https://github.com/cakesolutions/scala-kafka-client/wiki/KafkaConsumerActor-Configuration HOT 1
- Sharing Consumer or Producer threads across Actors
- In wiki, error in documentation (remove types from speficied parameters) HOT 2
- Cannot resolve version from Bintray nor Maven HOT 3
- how can get confirm finish offsets update or offsets successful ?
- I am using Maven and encountering The POM is missing error. HOT 3
- Wiki typos HOT 2
- client rediness for kafka 2.1.0 HOT 2
- Zookeeper Support
- Can't find Scala 2.13 packages HOT 8
- Add Support for Kafka 2.2.0 and Kafka 2.3.0
- Release into Maven Central
- Cached commit offsets can become stale and cause record replay after group rebalance HOT 1
- client readiness for kafka 2.4
- Is this library still mantained? HOT 2
- Bintray returns 403 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scala-kafka-client.