Google PubSub getMessageID = null because of a wrong tag?

I'm having a hard time getting the post id from the pubsub post from my subscriber. The problem is that the message pubsub stores the ID in the message_id field, but the getMessageId method looks for the message ID in the non-existent messageId field.

I am trying to get the post id from a Pubsub post that was posted from another application. The JSON request body looks like this:

{
    "message": {
        "data": "SomeEncodedDate",
        "attributes": {
            "Published_Timestamp": "1438970954798"
        },
        "message_id": "1325068255839"
    },
    "subscription": "projects/MyProject/subscriptions/MySubscription"
}

      

I can successfully recreate the message with the following code:

JsonParser parser = JacksonFactory.getDefaultInstance().createJsonParser(jsonRequest);
parser.skipToKey("message");
PubsubMessage message = parser.parseAndClose(PubsubMessage.class);

      

If I look at the message in the debugger, it has a valid message id in the message_id field. However, getMessageId () returns null. If I use the setMessageId ("SomeKey") method, then the message will contain a new messageId field with a new value. Now my message has two ID fields, message_id and messageId. The getMessageId call now returns the value of the messageId field, rather than the message_id, which was actually included in the pubsub message.

Is this a bug or am I doing something wrong?

+3


source to share


1 answer


Unfortunately I haven't found any other solution. The only thing I can do is copy the message code into the messageId field using: message.setMessageId (message.get ("message_id"). ToString ()); Then I can use the getMessageId method. This is just a mistake.



0


source







All Articles