The type EnableBinding is deprecated, The type StreamListener is deprecated - Spring Cloud Stream

Viewed 4461

I am using Spring Boot version 2.4.2 and doing Spring Cloud Stream and Spring Integration using @InboundChannelAdapter .

import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.annotation.InboundChannelAdapter;

@EnableBinding(value = Source.class)
public class TransactionPublisher {
    
    @InboundChannelAdapter(channel = Source.OUTPUT)
    public String sendTransactionDetails() {
        return "{name:\"T1\", amount: \"1000\", transactionFor : \"Purchase\"}";
    }
}

RabbitmqReceiverApplication.java

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;

@EnableBinding(value = Sink.class)
@SpringBootApplication
public class RabbitmqReceiverApplication {

    public static void main(String[] args) {
        SpringApplication.run(RabbitmqReceiverApplication.class, args);
    }

    @StreamListener(Sink.INPUT)
    public void log(String message) {
        System.out.println(message);
    }
}

What could be the alternative ? how to refactor the above code then? A lot of things are happening with the pace getting difficult to understand whats coming and whats going off ?

1 Answers

See the documentation.

e.g. On the consumer side...

@Bean
Consumer<String> log() {
    return str -> {
        System.out.println(str);
    };
}

The binding name is log-in-0.

On the producer side, it's a Supplier<String> bean with binding name sendTransactionDetails-out-0.

Related