jeudi 19 septembre 2019

Writing tests to verify received msg from pubsub using service activator (Spring-Boot)

Need to write the tests to verify the messages are consumed or not when published into pubsub, i used the spring integration concept to implement this.

Code to receive the messages from pubsub when published.

@SpringBootApplication

public class MyGcpSubPlanetApplication {

private static final Log LOGGER = LogFactory.getLog(MyGcpSubPlanetApplication.class);

public static void main(String[] args) {

  SpringApplication.run(MyGcpSubPlanetApplication.class, args);

}

@Bean public PubSubInboundChannelAdapter messageChannelAdapter( @Qualifier("myInputChannel") MessageChannel inputChannel, PubSubTemplate pubSubTemplate) {

  PubSubInboundChannelAdapter adapter =
        new PubSubInboundChannelAdapter(pubSubTemplate, "mySubscription");
  adapter.setOutputChannel(inputChannel);
  return adapter;

}

@Bean public MessageChannel myInputChannel() {

  return new DirectChannel();

}

@ServiceActivator(inputChannel = "myInputChannel")

public void messageReceiver(String payload) {

  LOGGER.info("Message arrived! Payload: " + payload);

}

}

Aucun commentaire:

Enregistrer un commentaire