Search in sources :

Example 1 with BasicAcknowledgeablePubsubMessage

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

the class PubSubChannelAdaptersIntegrationTests method sendAndReceiveMessageManualAck.

@Test
public void sendAndReceiveMessageManualAck() {
    this.contextRunner.withUserConfiguration(PollableConfiguration.class, CommonConfiguration.class).run((context) -> {
        context.getBean(PubSubInboundChannelAdapter.class).setAckMode(AckMode.MANUAL);
        context.getBean("inputChannel", MessageChannel.class).send(MessageBuilder.withPayload("I am a message (sendAndReceiveMessageManualAck).".getBytes()).build());
        PollableChannel channel = context.getBean("outputChannel", PollableChannel.class);
        Message<?> message = channel.receive(RECEIVE_TIMEOUT_MS);
        assertThat(message).isNotNull();
        BasicAcknowledgeablePubsubMessage origMessage = (BasicAcknowledgeablePubsubMessage) message.getHeaders().get(GcpPubSubHeaders.ORIGINAL_MESSAGE);
        assertThat(origMessage).isNotNull();
        origMessage.nack();
        message = channel.receive(RECEIVE_TIMEOUT_MS);
        assertThat(message).isNotNull();
        origMessage = (BasicAcknowledgeablePubsubMessage) message.getHeaders().get(GcpPubSubHeaders.ORIGINAL_MESSAGE);
        assertThat(origMessage).isNotNull();
        origMessage.ack();
        message = channel.receive(RECEIVE_TIMEOUT_MS);
        assertThat(message).isNull();
    });
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) PollableChannel(org.springframework.messaging.PollableChannel) BasicAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.BasicAcknowledgeablePubsubMessage) PubSubInboundChannelAdapter(org.springframework.cloud.gcp.pubsub.integration.inbound.PubSubInboundChannelAdapter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 PubSubInboundChannelAdapter (org.springframework.cloud.gcp.pubsub.integration.inbound.PubSubInboundChannelAdapter)1 BasicAcknowledgeablePubsubMessage (org.springframework.cloud.gcp.pubsub.support.BasicAcknowledgeablePubsubMessage)1 MessageChannel (org.springframework.messaging.MessageChannel)1 PollableChannel (org.springframework.messaging.PollableChannel)1