Warm_up
Warm_up

Reputation: 61

@Transformer for ObjectToJson Not Working in Spring Integration

A POJO Message.java is to be Converted to JSON(JSON is to be sent to pubsub Topic,using Spring Integration MessageChannels.),using following:

@Bean
    @Transformer(inputChannel = "pubsubOutputChannel", outputChannel = "handleOutChannel")
    public ObjectToJsonTransformer transformOut() {

        return new ObjectToJsonTransformer();
    }


    @MessagingGateway(defaultRequestChannel = "pubsubOutputChannel")
      public interface PubsubOutboundGateway {

        void sendToPubsub(Messages msg);
      }

    @Bean
      @ServiceActivator(inputChannel = "handleOutChannel")
      public MessageHandler messageSender(PubSubOperations pubsubTemplate) {
        return new PubSubMessageHandler(pubsubTemplate, "TestTopic");
      }

When i call sendToPubsub() with an instance of Message.java with required properties set,i get an error "Null".

Is serviceActivator not able to receive the required data? Any suggestions to fix this?.

Upvotes: 0

Views: 166

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121282

Yes, it can't do that because you just don't tell it to do that.

Your gateway is configured for this:

@MessagingGateway(defaultRequestChannel = "handleOutChannel")

But that is not an input channel for the ObjectToJsonTransformer. So, whatever you send over that gateway is going directly to the messageSender service activator.

Try to configure your gateway like this:

@MessagingGateway(defaultRequestChannel = "pubsubOutputChannel")

Upvotes: 1

Related Questions