Search in sources :

Example 1 with ConvertedAcknowledgeablePubsubMessage

use of org.springframework.cloud.gcp.pubsub.support.converter.ConvertedAcknowledgeablePubsubMessage in project spring-cloud-gcp by spring-cloud.

the class PubSubTemplateIntegrationTests method testPubSubTemplateLoadsMessageConverter.

@Test
public void testPubSubTemplateLoadsMessageConverter() {
    this.contextRunner.withUserConfiguration(JsonPayloadTestConfiguration.class).run((context) -> {
        PubSubAdmin pubSubAdmin = context.getBean(PubSubAdmin.class);
        PubSubTemplate pubSubTemplate = context.getBean(PubSubTemplate.class);
        String topicName = "json-payload-topic" + UUID.randomUUID();
        String subscriptionName = "json-payload-subscription" + UUID.randomUUID();
        pubSubAdmin.createTopic(topicName);
        pubSubAdmin.createSubscription(subscriptionName, topicName, 10);
        TestUser user = new TestUser("John", "password");
        pubSubTemplate.publish(topicName, user);
        await().atMost(Duration.TEN_SECONDS).untilAsserted(() -> {
            List<ConvertedAcknowledgeablePubsubMessage<TestUser>> messages = pubSubTemplate.pullAndConvert(subscriptionName, 1, true, TestUser.class);
            assertThat(messages).hasSize(1);
            TestUser receivedTestUser = messages.get(0).getPayload();
            assertThat(receivedTestUser.username).isEqualTo("John");
            assertThat(receivedTestUser.password).isEqualTo("password");
        });
        pubSubAdmin.deleteSubscription(subscriptionName);
        pubSubAdmin.deleteTopic(topicName);
    });
}
Also used : ConvertedAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.converter.ConvertedAcknowledgeablePubsubMessage) ByteString(com.google.protobuf.ByteString) PubSubTemplate(org.springframework.cloud.gcp.pubsub.core.PubSubTemplate) PubSubAdmin(org.springframework.cloud.gcp.pubsub.PubSubAdmin) Test(org.junit.Test)

Aggregations

ByteString (com.google.protobuf.ByteString)1 Test (org.junit.Test)1 PubSubAdmin (org.springframework.cloud.gcp.pubsub.PubSubAdmin)1 PubSubTemplate (org.springframework.cloud.gcp.pubsub.core.PubSubTemplate)1 ConvertedAcknowledgeablePubsubMessage (org.springframework.cloud.gcp.pubsub.support.converter.ConvertedAcknowledgeablePubsubMessage)1