use of org.springframework.cloud.gcp.pubsub.core.publisher.PubSubPublisherTemplate in project spring-cloud-gcp by spring-cloud.
the class GcpPubSubAutoConfiguration method pubSubPublisherTemplate.
@Bean
@ConditionalOnMissingBean
public PubSubPublisherTemplate pubSubPublisherTemplate(PublisherFactory publisherFactory, ObjectProvider<PubSubMessageConverter> pubSubMessageConverter) {
PubSubPublisherTemplate pubSubPublisherTemplate = new PubSubPublisherTemplate(publisherFactory);
pubSubMessageConverter.ifUnique(pubSubPublisherTemplate::setMessageConverter);
return pubSubPublisherTemplate;
}
use of org.springframework.cloud.gcp.pubsub.core.publisher.PubSubPublisherTemplate 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 org.springframework.cloud.gcp.pubsub.core.publisher.PubSubPublisherTemplate in project spring-cloud-gcp by spring-cloud.
the class PubSubTemplateTests method createPublisherTemplate.
private PubSubPublisherTemplate createPublisherTemplate() {
PubSubPublisherTemplate pubSubPublisherTemplate = new PubSubPublisherTemplate(this.mockPublisherFactory);
pubSubPublisherTemplate.setMessageConverter(new JacksonPubSubMessageConverter(new ObjectMapper()));
return pubSubPublisherTemplate;
}
Aggregations