Search in sources :

Example 1 with PubSubPublisherTemplate

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;
}
Also used : PubSubPublisherTemplate(org.springframework.cloud.gcp.pubsub.core.publisher.PubSubPublisherTemplate) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with 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));
}
Also used : PubSubPublisherTemplate(org.springframework.cloud.gcp.pubsub.core.publisher.PubSubPublisherTemplate) AllowedPayload(org.springframework.cloud.gcp.pubsub.core.test.allowed.AllowedPayload) PubsubMessage(com.google.pubsub.v1.PubsubMessage) Test(org.junit.Test)

Example 3 with PubSubPublisherTemplate

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;
}
Also used : PubSubPublisherTemplate(org.springframework.cloud.gcp.pubsub.core.publisher.PubSubPublisherTemplate) JacksonPubSubMessageConverter(org.springframework.cloud.gcp.pubsub.support.converter.JacksonPubSubMessageConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

PubSubPublisherTemplate (org.springframework.cloud.gcp.pubsub.core.publisher.PubSubPublisherTemplate)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 PubsubMessage (com.google.pubsub.v1.PubsubMessage)1 Test (org.junit.Test)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 AllowedPayload (org.springframework.cloud.gcp.pubsub.core.test.allowed.AllowedPayload)1 JacksonPubSubMessageConverter (org.springframework.cloud.gcp.pubsub.support.converter.JacksonPubSubMessageConverter)1 Bean (org.springframework.context.annotation.Bean)1