@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.pubsub.v1.PubsubMessage)) { return super.equals(obj); } com.google.pubsub.v1.PubsubMessage other = (com.google.pubsub.v1.PubsubMessage) obj; boolean result = true; result = result && getData().equals(other.getData()); result = result && internalGetAttributes().equals(other.internalGetAttributes()); result = result && getMessageId().equals(other.getMessageId()); result = result && (hasPublishTime() == other.hasPublishTime()); if (hasPublishTime()) { result = result && getPublishTime().equals(other.getPublishTime()); } result = result && unknownFields.equals(other.unknownFields); return result; }
attributes.put(MESSAGE_ID_ATTRIBUTE, message.getMessage().getMessageId()); attributes.put(MSG_ATTRIBUTES_COUNT_ATTRIBUTE, String.valueOf(message.getMessage().getAttributesCount())); attributes.put(MSG_PUBLISH_TIME_ATTRIBUTE, String.valueOf(message.getMessage().getPublishTime().getSeconds())); attributes.putAll(message.getMessage().getAttributesMap()); flowFile = session.write(flowFile, out -> out.write(message.getMessage().getData().toByteArray()));
@Override public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) { // handle incoming message, then ack/nack the received message System.out.println("Id : " + message.getMessageId()); System.out.println("Data : " + message.getData().toStringUtf8()); consumer.ack(); } };
/** * * * <pre> * The message data field. If this field is empty, the message must contain * at least one attribute. * </pre> * * <code>bytes data = 1;</code> */ public Builder clearData() { data_ = getDefaultInstance().getData(); onChanged(); return this; }
public Builder mergeFrom(com.google.pubsub.v1.PubsubMessage other) { if (other == com.google.pubsub.v1.PubsubMessage.getDefaultInstance()) return this; if (other.getData() != com.google.protobuf.ByteString.EMPTY) { setData(other.getData()); } internalGetMutableAttributes().mergeFrom(other.internalGetAttributes()); if (!other.getMessageId().isEmpty()) { messageId_ = other.messageId_; onChanged(); } if (other.hasPublishTime()) { mergePublishTime(other.getPublishTime()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@Override public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) { String messagePayload = message.getData().toStringUtf8(); String messageId = message.getMessageId(); Map messageAttributes = message.getAttributesMap() == null ? new HashMap<>() : message.getAttributesMap(); log.debug("Received Google pub/sub message with payload: {}\n and attributes: {}", messagePayload, messageAttributes); MessageDescription description = MessageDescription.builder() .subscriptionName(subscriptionName) .messagePayload(messagePayload) .messageAttributes(messageAttributes) .pubsubSystem(pubsubSystem) .ackDeadlineMillis(5 * TimeUnit.SECONDS.toMillis(ackDeadlineSeconds)) // Set a high upper bound on message processing time. .retentionDeadlineMillis(TimeUnit.DAYS.toMillis(7)) // Expire key after max retention time, which is 7 days. .build(); GoogleMessageAcknowledger acknowledger = new GoogleMessageAcknowledger(consumer); try { List<Artifact> artifacts = messageArtifactTranslator.parseArtifacts(messagePayload); description.setArtifacts(artifacts); log.info("artifacts {}", String.join(", ", artifacts.stream().map(Artifact::toString).collect(Collectors.toList()))); } catch (Exception e) { log.error("Failed to process artifacts: {}", e.getMessage(), e); pubsubMessageHandler.handleFailedMessage(description, acknowledger, identity.getIdentity(), messageId); return; } pubsubMessageHandler.handleMessage(description, acknowledger, identity.getIdentity(), messageId); } }
@Override public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) { System.out.println("Received message: " + message.getData().toStringUtf8()); consumer.ack(); } };
@java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (!data_.isEmpty()) { output.writeBytes(1, data_); } com.google.protobuf.GeneratedMessageV3.serializeStringMapTo( output, internalGetAttributes(), AttributesDefaultEntryHolder.defaultEntry, 2); if (!getMessageIdBytes().isEmpty()) { com.google.protobuf.GeneratedMessageV3.writeString(output, 3, messageId_); } if (publishTime_ != null) { output.writeMessage(4, getPublishTime()); } unknownFields.writeTo(output); }
.publish(PubsubMessage.newBuilder().setData(ByteString.copyFromUtf8("msg1")).build()) .get(); publisher .publish(PubsubMessage.newBuilder().setData(ByteString.copyFromUtf8("msg2")).build()) .get(); publisher.shutdown(); assertThat(toNack.message().getData()).isNotEqualTo(toAck.message().getData()); toNack.consumer().nack(); assertThat(redelivered.message().getData()).isEqualTo(toNack.message().getData()); redelivered.consumer().ack();
for (ReceivedMessage message : response.getReceivedMessagesList()) { PubsubMessage pubsubMessage = message.getMessage(); @Nullable Map<String, String> attributes = pubsubMessage.getAttributes(); byte[] elementBytes = pubsubMessage.getData().toByteArray(); Timestamp timestampProto = pubsubMessage.getPublishTime(); if (timestampProto != null) { pubsubTimestampString = recordId = pubsubMessage.getMessageId();
.build(), (pubsubMessage, ackReplyConsumer) -> { if (pubsubMessage.getAttributesCount() > 0 && pubsubMessage.getAttributesMap().get("DlpJobName").equals(dlpJobName)) {
/** * * * <pre> * ID of this message, assigned by the server when the message is published. * Guaranteed to be unique within the topic. This value may be read by a * subscriber that receives a `PubsubMessage` via a `Pull` call or a push * delivery. It must not be populated by the publisher in a `Publish` call. * </pre> * * <code>string message_id = 3;</code> */ public Builder clearMessageId() { messageId_ = getDefaultInstance().getMessageId(); onChanged(); return this; } /**
Map<String, String> messageAttributes = message.getAttributes(); String key = messageAttributes.get(kafkaMessageKeyAttribute); Long timestamp = getLongValue(messageAttributes.get(kafkaMessageTimestampAttribute)); if (timestamp == null){ timestamp = Timestamps.toMillis(message.getPublishTime()); ByteString messageData = message.getData(); byte[] messageBytes = messageData.toByteArray();
/** Use {@link #getAttributesMap()} instead. */ @java.lang.Deprecated public java.util.Map<java.lang.String, java.lang.String> getAttributes() { return getAttributesMap(); } /**
/** * * * <pre> * The time at which the message was published, populated by the server when * it receives the `Publish` call. It must not be populated by the * publisher in a `Publish` call. * </pre> * * <code>.google.protobuf.Timestamp publish_time = 4;</code> */ public com.google.protobuf.TimestampOrBuilder getPublishTimeOrBuilder() { return getPublishTime(); }
@java.lang.Override public com.google.pubsub.v1.PubsubMessage buildPartial() { com.google.pubsub.v1.PubsubMessage result = new com.google.pubsub.v1.PubsubMessage(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; result.data_ = data_; result.attributes_ = internalGetAttributes(); result.attributes_.makeImmutable(); result.messageId_ = messageId_; if (publishTimeBuilder_ == null) { result.publishTime_ = publishTime_; } else { result.publishTime_ = publishTimeBuilder_.build(); } result.bitField0_ = to_bitField0_; onBuilt(); return result; }
public Builder mergeFrom(com.google.pubsub.v1.PubsubMessage other) { if (other == com.google.pubsub.v1.PubsubMessage.getDefaultInstance()) return this; if (other.getData() != com.google.protobuf.ByteString.EMPTY) { setData(other.getData()); } internalGetMutableAttributes().mergeFrom( other.internalGetAttributes()); if (!other.getMessageId().isEmpty()) { messageId_ = other.messageId_; onChanged(); } if (other.hasPublishTime()) { mergePublishTime(other.getPublishTime()); } onChanged(); return this; }
@Override public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) { String messagePayload = message.getData().toStringUtf8(); String messageId = message.getMessageId(); Map messageAttributes = message.getAttributesMap() == null ? new HashMap<>() : message.getAttributesMap(); log.debug("Received Google pub/sub message with payload: {}\n and attributes: {}", messagePayload, messageAttributes); MessageDescription description = MessageDescription.builder() .subscriptionName(subscriptionName) .messagePayload(messagePayload) .messageAttributes(messageAttributes) .pubsubSystem(pubsubSystem) .ackDeadlineSeconds(5 * ackDeadlineSeconds) // Set a high upper bound on message processing time. .retentionDeadlineSeconds(7 * 24 * 60 * 60) // Expire key after max retention time, which is 7 days. .build(); GoogleMessageAcknowledger acknowledger = new GoogleMessageAcknowledger(consumer); try { List<Artifact> artifacts = messageArtifactTranslator.parseArtifacts(messagePayload); description.setArtifacts(artifacts); log.info("artifacts {}", String.join(", ", artifacts.stream().map(Artifact::toString).collect(Collectors.toList()))); } catch (Exception e) { log.error("Failed to process artifacts: {}", e.getMessage(), e); pubsubMessageHandler.handleFailedMessage(description, acknowledger, identity.getIdentity(), messageId); return; } pubsubMessageHandler.handleMessage(description, acknowledger, identity.getIdentity(), messageId); } }
@Override public synchronized void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) { // Every time a Pub/Sub message comes in, print it and count it System.out.println("Message " + messageCount + ": " + message.getData().toStringUtf8()); messageCount += 1; // Acknowledge the message consumer.ack(); } }