use of com.google.pubsub.v1.PubsubMessage in project spring-cloud-gcp by spring-cloud.
the class SimplePubSubMessageConverterTests method testNullHeaders.
@Test
public void testNullHeaders() {
SimplePubSubMessageConverter converter = new SimplePubSubMessageConverter();
PubsubMessage pubsubMessage = converter.toPubSubMessage(TEST_STRING, null);
assertThat(pubsubMessage.getData().toString(Charset.defaultCharset())).isEqualTo(TEST_STRING);
assertThat(pubsubMessage.getAttributesMap()).isEqualTo(new HashMap<>());
}
use of com.google.pubsub.v1.PubsubMessage in project spring-cloud-gcp by spring-cloud.
the class PubSubSubscriberTemplate method pullAndAckAsync.
@Override
public ListenableFuture<List<PubsubMessage>> pullAndAckAsync(String subscription, Integer maxMessages, Boolean returnImmediately) {
PullRequest pullRequest = this.subscriberFactory.createPullRequest(subscription, maxMessages, returnImmediately);
final SettableListenableFuture<List<PubsubMessage>> settableFuture = new SettableListenableFuture<>();
this.pullAsync(pullRequest).addCallback(ackableMessages -> {
if (!ackableMessages.isEmpty()) {
ack(ackableMessages);
}
List<PubsubMessage> messages = ackableMessages.stream().map(AcknowledgeablePubsubMessage::getPubsubMessage).collect(Collectors.toList());
settableFuture.set(messages);
}, settableFuture::setException);
return settableFuture;
}
use of com.google.pubsub.v1.PubsubMessage in project spring-cloud-gcp by spring-cloud.
the class PubSubSubscriberTemplate method pullAndAck.
@Override
public List<PubsubMessage> pullAndAck(String subscription, Integer maxMessages, Boolean returnImmediately) {
PullRequest pullRequest = this.subscriberFactory.createPullRequest(subscription, maxMessages, returnImmediately);
List<AcknowledgeablePubsubMessage> ackableMessages = pull(pullRequest);
if (!ackableMessages.isEmpty()) {
ack(ackableMessages);
}
return ackableMessages.stream().map(AcknowledgeablePubsubMessage::getPubsubMessage).collect(Collectors.toList());
}
use of com.google.pubsub.v1.PubsubMessage in project spring-cloud-gcp by spring-cloud.
the class PubSubTemplateTests method testPublish_Object.
@Test
public void testPublish_Object() throws IOException {
AllowedPayload allowedPayload = new AllowedPayload();
allowedPayload.name = "allowed";
allowedPayload.value = 12345;
PubSubPublisherTemplate pubSubPublisherTemplate = spy(createPublisherTemplate());
doAnswer((invocation) -> {
PubsubMessage message = invocation.getArgument(1);
assertThat(message.getData().toStringUtf8()).isEqualTo("{\"@class\":" + "\"org.springframework.cloud.gcp.pubsub.core.test.allowed.AllowedPayload\"" + ",\"name\":\"allowed\",\"value\":12345}");
return null;
}).when(pubSubPublisherTemplate).publish(eq("test"), any());
pubSubPublisherTemplate.publish("test", allowedPayload);
verify(pubSubPublisherTemplate, times(1)).publish(eq("test"), isA(PubsubMessage.class));
}
use of com.google.pubsub.v1.PubsubMessage in project spring-cloud-gcp by spring-cloud.
the class JacksonPubSubMessageConverterTests method testString.
@Test
public void testString() throws JSONException {
String str = "test 123";
PubsubMessage pubsubMessage = this.converter.toPubSubMessage(str, null);
JSONAssert.assertEquals("\"test 123\"", pubsubMessage.getData().toStringUtf8(), true);
Object o = this.converter.fromPubSubMessage(pubsubMessage, String.class);
assertThat(o).as("verify that deserialized object is equal to the original one").isEqualTo(str);
}
Aggregations