Search code examples
serializationapache-stormtrident

Client serialization issue: read from Couchbase in Trident function


Basically, I want to read some additional attributes from Couchbase with attributes from the tuple, for example, the tuple has input fields "{a, b, c}", I want to emit a tuple "{a, b, c, d, e}" where "d" and "e" are read from Couchbase with "a" as the key.

However, Trident BaseFunction is serializable while CouchbaseClient is not, which leads "NotSerializable" exception, is there anyway to get around this? There are two possible solutions I can think of:

1) read the additional attributes outside Trident and send them together to Trident (I don't want to do this cause I want to put this kind of processing in Storm)

2) Use state, which is read-only (only implement multi-get, leaving multi-put blank, not sure whether this will do the trick)

Is there any easy way to do this? This should be dorable in Storm itself and is pretty common in real world. It also applies to other NoSQL db like Cassandra. Thanks.


Solution

  • You can create your database connection in the prepare() method of your Function or use a queryState to lookup all the values at once for the batch.