Skip to content

Conversation

@anguillanneuf
Copy link
Contributor

Fixes #856

Show the proper way to publish a message to Pub/Sub Lite with an event time as an attribute.

@product-auto-label product-auto-label bot added api: pubsublite Issues related to the googleapis/java-pubsublite API. samples Issues that are directly related to samples. labels Sep 8, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Sep 8, 2021
System.out.println("Data : " + message.getData().toStringUtf8());
System.out.println("Ordering key : " + message.getOrderingKey());
System.out.println("Attributes : ");
message
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also demonstrate extracting the event time

MessageTransforms. decodeAttributeEventTime(message.getAttributesMap().get(MessageTransforms.PUBSUB_LITE_EVENT_TIME_TIMESTAMP_PROTO))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a generic SubscriberExample for messages with and without attributes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay. Thats fine then. Could you add:

if (message.getAttributesMap().containsKey(MessageTransforms.PUBSUB_LITE_EVENT_TIME_TIMESTAMP_PROTO)) {
  System.out.println("Event timestamp : ", + MessageTransforms. decodeAttributeEventTime(message.getAttributesMap().get(MessageTransforms.PUBSUB_LITE_EVENT_TIME_TIMESTAMP_PROTO)));
}

Copy link
Contributor Author

@anguillanneuf anguillanneuf Sep 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, a if..else exists in the last commit.

@anguillanneuf anguillanneuf merged commit d2b7afe into master Sep 8, 2021
@anguillanneuf anguillanneuf deleted the eventtime branch September 8, 2021 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: pubsublite Issues related to the googleapis/java-pubsublite API. cla: yes This human has signed the Contributor License Agreement. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need a more obvious way to set event time in a message

3 participants