@Override public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) { System.out.println("Received message: " + message.getData().toStringUtf8()); consumer.ack(); } };
@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; }
@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; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + DATA_FIELD_NUMBER; hash = (53 * hash) + getData().hashCode(); if (!internalGetAttributes().getMap().isEmpty()) { hash = (37 * hash) + ATTRIBUTES_FIELD_NUMBER; hash = (53 * hash) + internalGetAttributes().hashCode(); } hash = (37 * hash) + MESSAGE_ID_FIELD_NUMBER; hash = (53 * hash) + getMessageId().hashCode(); if (hasPublishTime()) { hash = (37 * hash) + PUBLISH_TIME_FIELD_NUMBER; hash = (53 * hash) + getPublishTime().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
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; }
flowFile = session.write(flowFile, out -> out.write(message.getMessage().getData().toByteArray()));
@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(); } }
/** Receive messages over a subscription. */ public static void main(String... args) throws Exception { // set subscriber id, eg. my-sub String subscriptionId = args[0]; ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of( PROJECT_ID, subscriptionId); Subscriber subscriber = null; try { // create a subscriber bound to the asynchronous message receiver subscriber = Subscriber.newBuilder(subscriptionName, new MessageReceiverExample()).build(); subscriber.startAsync().awaitRunning(); // Continue to listen to messages while (true) { PubsubMessage message = messages.take(); System.out.println("Message Id: " + message.getMessageId()); System.out.println("Data: " + message.getData().toStringUtf8()); } } finally { if (subscriber != null) { subscriber.stopAsync(); } } } }
@Override public <T> T fromPubSubMessage(PubsubMessage message, Class<T> payloadType) { try { return (T) this.objectMapper.readerFor(payloadType).readValue(message.getData().toByteArray()); } catch (IOException ex) { throw new PubSubMessageConversionException("JSON deserialization of an object of type " + payloadType.getName() + " failed.", ex); } }
@Override public <T> T fromPubSubMessage(PubsubMessage message, Class<T> payloadType) { try { return (T) this.objectMapper.readerFor(payloadType).readValue(message.getData().toByteArray()); } catch (IOException ex) { throw new PubSubMessageConversionException("JSON deserialization of an object of type " + payloadType.getName() + " failed.", ex); } }
@GetMapping("/subscribe") public RedirectView subscribe(@RequestParam("subscription") String subscriptionName) { Subscriber subscriber = this.pubSubTemplate.subscribe(subscriptionName, (message) -> { LOGGER.info("Message received from " + subscriptionName + " subscription: " + message.getPubsubMessage().getData().toStringUtf8()); message.ack(); }); this.allSubscribers.add(subscriber); return buildStatusView("Subscribed."); }
/** * <code>optional bytes data = 1;</code> * * <pre> * The message payload. For JSON requests, the value of this field must be * base64-encoded. * </pre> */ public Builder clearData() { data_ = getDefaultInstance().getData(); onChanged(); return this; }
/** * <pre> * The message payload. For JSON requests, the value of this field must be * [base64-encoded](https://tools.ietf.org/html/rfc4648). * </pre> * * <code>optional bytes data = 1;</code> */ public Builder clearData() { data_ = getDefaultInstance().getData(); onChanged(); return this; }
/** * * * <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; }
@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; }
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; }
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; }
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; }