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

1402 views java

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:

    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:


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


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

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

import org.msgpack.value.ValueFactory;


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?


Please login first before posting an answer.