Apache beam with MessagePack - how do I get values from Map<Value, Value>?

1402 views java
3

Inside an Apache Beam transform I can successfully transform pub/sub values (in MessagePack format) that I read from Google Cloud Pub/Sub into a map of MessagePack Value objects like this:

    @ProcessElement
    public void processElement(ProcessContext c) 
    {
        Map<Value, Value> map = MessagePack.newDefaultUnpacker(c.element().getPayload()).unpackValue().asMapValue().map();

When I inspect map I can see the following:

enter image description here

If I then try to get a value like this it always returns null:

map.get("Tz")

How do I get a value? Do I need to transform the values in a different way, or do I need a different way of retrieving them?

answered question

2 Answers

8

The map is Map, so the key is a value object, but you are using a String s the key when you do map.get("Tz")

Can you create a Value object using Tz and attempt to get based on that Value object?

posted this
5

I needed to do this to retrieve the values as strings:

import org.msgpack.value.ValueFactory;

map.get(ValueFactory.newString("Tz")).toString()

See also In messagepack, error while getting value from MapValue.. Please help me (the solution didn't work in my case, but there are some suggestions there for dealing with different types that can be used in a Map)

posted this

Have an answer?

JD

Please login first before posting an answer.