Search in sources :

Example 1 with PubSubMessageHandler

use of org.springframework.cloud.gcp.pubsub.integration.outbound.PubSubMessageHandler in project spring-cloud-gcp by spring-cloud.

the class SenderApplication method messageSender.

@Bean
@ServiceActivator(inputChannel = "pubSubOutputChannel")
public MessageHandler messageSender(PubSubTemplate pubsubTemplate) {
    PubSubMessageHandler adapter = new PubSubMessageHandler(pubsubTemplate, "exampleTopic");
    adapter.setPublishCallback(new ListenableFutureCallback<String>() {

        @Override
        public void onFailure(Throwable ex) {
            LOGGER.info("There was an error sending the message.");
        }

        @Override
        public void onSuccess(String result) {
            LOGGER.info("Message was sent successfully.");
        }
    });
    return adapter;
}
Also used : PubSubMessageHandler(org.springframework.cloud.gcp.pubsub.integration.outbound.PubSubMessageHandler) ServiceActivator(org.springframework.integration.annotation.ServiceActivator) Bean(org.springframework.context.annotation.Bean)

Aggregations

PubSubMessageHandler (org.springframework.cloud.gcp.pubsub.integration.outbound.PubSubMessageHandler)1 Bean (org.springframework.context.annotation.Bean)1 ServiceActivator (org.springframework.integration.annotation.ServiceActivator)1